VMware Cloud Community
vin01
Expert
Expert

complete vm info

Hi

I need complete vm information for two datacenters for that i used below script i know it is very time taking process with this script but i waited for 1 week for 2500 vms but after a week it collected for 10 clusters and stopped(i mean script is executing but no data is writing) can any please help out to collect data in a quick way with any other script.

ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {

ForEach ($Cluster in ($Datacenter | Get-Cluster  | Sort-Object -Property Name)) {

   ForEach ($VM in ($Cluster | Get-VM  | Sort-Object -Property Name)) {

      ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name))

{

        $ds = Get-Datastore -Name ($HardDisk.FileName.Split("]")[0].TrimStart("[")) |

         Select -First 1

        $dsLun = @()

        $dsLunID = @()

        $dsWwwn = @()

        Get-ScsiLun -Datastore $ds | Sort-Object -Property CanonicalName -Unique | %{  

         $dsLun += $_.CanonicalName         

        $dsLunID += $_.RunTimeName.Split(':')[-1].Trim('L')

        }       

        $esx = Get-VMHost -Name $vm.VMHost.Name

        $lunKey = @()                      

        $lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun |         

         where {$dsLun -contains $_.CanonicalName} | %{$_.Key}       

       $lunWWN = @()

       $lunWWN = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun |

       where {$lunKey -contains $_.Lun} | %{

       $_.Path | %{"{0:x}" -f $_.Transport.NodeWorldWideName}         

      } | Sort-Object -Unique      

"" | Select-Object -Property @{N="VM";E={$VM.Name}},

@{N="VMIP1";E={$vm.Guest.IPAddress[0]}},

@{N="VMIP2";E={$vm.Guest.IPAddress[1]}},

@{N="VMIP3";E={$vm.Guest.IPAddress[2]}},      

@{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},      

@{N="VM CPU Core#";E={$vm.NumCPU}},

@{N="Datacenter";E={$Datacenter.name}},

@{N="Cluster";E={$Cluster.Name}},

@{N="Host";E={$vm.VMHost.Name}},

@{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},

@{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},

@{N="Hard Disk";E={$HardDisk.Name}},

@{N="Datastore";E={$ds.Name}},

@{N="LUN";E={[string]::Join(',',$dsLun)}},

@{N="LUNID";E={[string]::Join(',',$dsLunId)}},

@{N="LUNWWN";E={[string]::Join(',',$lunWWN)}},

@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},

@{N="VMDKpath";E={$HardDisk.FileName}},

@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},

@{N="Drive Size";E={$HardDisk.CapacityGB}}

    }   

   } 

  }

}

Regards Vineeth.K
17 Replies
vin01
Expert
Expert

Can any one please help me...Is the above script is right way to collect info or any alternate is avaliable..

Regards Vineeth.K
0 Kudos
LucD
Leadership
Leadership

Any method to achieve the desired result is a correct one.

But there are some improvements to be made if you want to improve the execution time.

The Get-ScsiLun cmdlet is a rather time consuming one, and you execute this for every harddisk.

It could improve the total execution time of the script, if you would do perhaps 1 call to Get-ScsiLun and collect the returned information in a hash table.

You could then lookup the information from the hash table by using the datastorename as the key.

Same is true, albeit to a lesser extent, for the Get-Datastore and Get-VMHost cmdlets you call for every harddisk.

And finally, if you run a script against a bigger environment, it could be worth your while to pass to the Get-View cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vin01
Expert
Expert

Thanks LucD for your reply...

Can you help me what improvements should i do to increase the execution time.Yes Get-ScsiLun will be exectuted for every harddisk.,So how to give single call to all harddisk and write the information in hash table and same can be lookup by datastore name.

Yes this is running on larger environment.I'm not that familer to rewrite the whole script.Can you improve the script for faster output.

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert

Hi LucD

Tried in different ways to pull the vm information but all leads to time taking process and after executing for some time it will stop collecting data...can you consoldate for fast output.

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert

Hi LucD..I'm unable to consoldate properly can you rewrite the script to improve the execution time.I need to  run this on big environment.script is stop writing after some hours..

Regards Vineeth.K
0 Kudos
dajbozerozum
Contributor
Contributor

Read about Get-View -ViewType VirtualMachine. This should quite reduce time execution of script.

0 Kudos
kunaludapi
Expert
Expert

Check out below, this should make some improvement

$Scsilun = Get-ScsiLun

$Datastore = Get-Datastore

ForEach ($Datacenter in (Get-Datacenter)) {

    ForEach ($Cluster in ($Datacenter | Get-Cluster)) {

        ForEach ($VM in ($Cluster |  Get-VM)) {

            ForEach ($HardDisk in ($VM | Get-HardDisk)) {

                $ds = Get-Datastore -Name $($HardDisk.FileName.Split("]")[0].TrimStart("[")) | Select -First 1

                $dsLun = @()

                $dsLunID = @()

                $dsWwwn = @()

                $Scsilun | Where-Object {$_.CanonicalName -match $ds.extensiondata.info.vmfs.Extent.DiskName} | % {

                    $dsLun += $_.CanonicalName       

                    $dsLunID += $_.RunTimeName.Split(':')[-1].Trim('L')

                    }

                $esx = Get-VMHost -Name $vm.VMHost.Name

                $lunKey = @()

                $lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object {$dsLun -contains $_.CanonicalName} | % {$_.Key}

                $lunWWN = @()

                $lunWWN = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object {$lunKey -contains $_.Lun} | % {$_.Path | %{"{0:x}" -f $_.Transport.NodeWorldWideName}}    

                  

                    "" | Select-Object -Property @{N="VM";E={$VM.Name}},

                    @{N="VMIP1";E={$vm.Guest.IPAddress[0]}},

                    @{N="VMIP2";E={$vm.Guest.IPAddress[1]}},

                    @{N="VMIP3";E={$vm.Guest.IPAddress[2]}},    

                    @{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},    

                    @{N="VM CPU Core#";E={$vm.NumCPU}},

                    @{N="Datacenter";E={$Datacenter.name}},

                    @{N="Cluster";E={$Cluster.Name}},

                    @{N="Host";E={$vm.VMHost.Name}},

                    @{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},

                    @{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},

                    @{N="Hard Disk";E={$HardDisk.Name}},

                    @{N="Datastore";E={$ds.Name}},

                    @{N="LUN";E={[string]::Join(',',$dsLun)}},

                    @{N="LUNID";E={[string]::Join(',',$dsLunId)}},

                    @{N="LUNWWN";E={[string]::Join(',',$lunWWN)}},

                    @{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},

                    @{N="VMDKpath";E={$HardDisk.FileName}},

                    @{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},

                    @{N="Drive Size";E={$HardDisk.CapacityGB}}

            }

        }

    }

}

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
vin01
Expert
Expert

Hi Kunal

Sorry for delay response, Thanks for your reply...Right Now i'm executing this script over 3000 vms..lets see the execution time ill get back you after completing..

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert

Hi Kunal

I tried this script.. Its showing below errors..

error.jpg

Should i need to change

$Scsilun = Get-ScsiLun  to $Scsilun = Get-VMhost |Get-ScsiLun

================================

its not writing complete out put like Lun,Lunid,LunWWN..Sample output for above script..

VMVMIP1VMIP2VMIP3VM CPU#VM CPU Core#DatacenterClusterHostHost CPU#Host CPU Core#Hard DiskDatastoreLUNLUNIDLUNWWNVMConfigFileVMDKpathVMDK SizeDrive Size
testvm10.xx.xx.xxfe80::5c8d:b3b1:24ec:e9c812test dctestcluster10.xx.xx.xxxxHard disk 1datastore1datastore/test.vmxdatastore/test.vmdk4040
Regards Vineeth.K
0 Kudos
vin01
Expert
Expert

Hi Kunal

Can you rewrite the script to clear the above given error...

Regards Vineeth.K
0 Kudos
kunaludapi
Expert
Expert

Thanks, Got a new learning today, Yes you are correct.

Change the first line to

$Scsilun = Get-VMhost | Get-ScsiLun

I was testing above script against single host.

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
vin01
Expert
Expert

thanks for reply kunal..I tried this by changing the first line on script..Run the script on 3000 vms..this  was executed more than 8hrs writing no output..can you try one single host and correct me..if anything I should change while executing on large environment..

Regards Vineeth.K
0 Kudos
kunaludapi
Expert
Expert

I ran this script over vCenter environment, I am able to see output except lunwwn.

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
vin01
Expert
Expert

Hi Kunal

Kindly ignore my delay..little bit busy on another activites..I executed the above report but we need to fine tune the script..

In Breif :

In Lun coloum its writing all datastore wwn details..As we need only wwn of the datastore which is in "datastore cloumn" written on output.

Same to Lun ID its writing all Lunid details..As we need only Lunid of the datastore which is in "datastore cloumn" written on output.

In LunWWN its is writing all wwndetails..As we need only wwn of that particular vm where it is hosting..

=========

Its very large output i can't pase here..If any query on above explanation do reply here i will clarify..

Regards Vineeth.K
0 Kudos
esxi1979
Expert
Expert

This one is nice .. Can you add below fileds as well.. (ignire syntax)

======================================================================================================================================================

'Real-OS'= $vm.guest.OSFullName; 

           'Setting-OS' = $VM.ExtensionData.summary.config.guestfullname;

           'Domain Name'= ($vm.ExtensionData.Guest.Hostname -split '\.')[1,2] -join '.';           

      

           'RAM(GB)'= $vm.MemoryGB; 

            'Folder'= $vm.folder; 

           'MacAddress' = ($vm | Get-NetworkAdapter).MacAddress -join ", ";

           'VMTools Status' = $vm.ExtensionData.Guest.ToolsStatus; 

           'VMTools Version' = $vm.ExtensionData.Guest.ToolsVersion; 

           'VMTools Version Status' = $vm.ExtensionData.Guest.ToolsVersionStatus; 

           'VMTools Running Status' = $vm.ExtensionData.Guest.ToolsRunningStatus; 

             'SnapShots' = ($vm | get-snapshot).count; 

            

              $VMInfo.Powerstate = $vm.Powerstate

      $VMInfo.OS = $vm.Guest.OSFullName

      $VMInfo.Folder = ($vm | Get-Folderpath).Path

    $vms.CPUAffinity = $vm.Config.CpuAffinity

$vms.CPUHotAdd = $vm.Config.CpuHotAddEnabled

$vms.CPUShare = $vm.Config.CpuAllocation.Shares.Level

$vms.TimeSync = $vm.Config.Tools.SyncTimeWithHost

$vms.HardwareVersion = $vm.config.Version

    $vms.MemoryLimit = $vm.resourceconfig.memoryallocation.limit

    $vms.MemoryReservation = $vm.resourceconfig.memoryallocation.reservation

    $vms.CPUreservation = $vm.resourceconfig.cpuallocation.reservation

    $vms.CPUlimit = $vm.resourceconfig.cpuallocation.limit

$vms.CBT = $vm.Config.ChangeTrackingEnabled

$vms.Swapped = $vm.Summary.QuickStats.SwappedMemory

$vms.Ballooned = $vm.Summary.QuickStats.BalloonedMemory

$vms.Compressed = $vm.Summary.QuickStats.CompressedMemory

$PortGroup = @($PortGroups | Where-Object {$_.name -eq $dev.DeviceInfo.summary})[0]

======================================================================================================================================================

0 Kudos
vin01
Expert
Expert

$Scsilun = Get-VMHost |Get-ScsiLun

$Datastore = Get-Datastore

ForEach ($Datacenter in (Get-Datacenter)) {

ForEach ($Cluster in ($Datacenter | Get-Cluster)) {

ForEach ($VM in ($Cluster |  Get-VM)) {

ForEach ($HardDisk in ($VM | Get-HardDisk)) {

$ds = Get-Datastore -Name $($HardDisk.FileName.Split("]")[0].TrimStart("[")) | Select -First 1

$dsLun = @()

$dsLunID = @()

$dsWwwn = @()

$Scsilun | Where-Object {$_.CanonicalName -match $ds.extensiondata.info.vmfs.Extent.DiskName} | %{

$dsLun += $_.CanonicalName        

$dsLunID += $_.RunTimeName.Split(':')[-1].Trim('L')

}

$esx = Get-VMHost -Name $vm.VMHost.Name

$lunKey = @()

$lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object {$dsLun -contains $_.CanonicalName} | % {$_.Key}

$lunWWN = @()

$lunWWN = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object {$lunKey -contains $_.Lun} | % {$_.Path | %{"{0:x}" -f $_.Transport.NodeWorldWideName}}      

"" | Select-Object -Property @{N="VM";E={$VM.Name}},

@{N="VMIP1";E={$vm.Guest.IPAddress[0]}},

@{N="VMIP2";E={$vm.Guest.IPAddress[1]}},

@{N="VMIP3";E={$vm.Guest.IPAddress[2]}},     

@{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},     

@{N="VM CPU Core#";E={$vm.NumCPU}},

@{N="Datacenter";E={$Datacenter.name}},

@{N="Cluster";E={$Cluster.Name}},

@{N="Host";E={$vm.VMHost.Name}},

@{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},

@{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},

@{N="Hard Disk";E={$HardDisk.Name}},

@{N="Datastore";E={$ds.Name}},

@{N="LUN";E={[string]::Join(',',$dsLun)}},

@{N="LUNID";E={[string]::Join(',',$dsLunId)}},

@{N="LUNWWN";E={[string]::Join(',',$lunWWN)}},

@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},

@{N="VMDKpath";E={$HardDisk.FileName}},

@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},

@{N="Drive Size";E={$HardDisk.CapacityGB}}

}

}

}

}

Can any one correct this script..while exectuing this its not writing desired output..

For Example :

In Lun coloum its writing all datastore wwn details..As we need only wwn of the datastore which is in "datastore cloumn" written on output.

Same to Lun ID its writing all Lunid details..As we need only Lunid of the datastore which is in "datastore cloumn" written on output.

In "LunWWN" its is writing all wwndetails..As we need only wwn of that particular vm where it is hosting..

=========

Its very large output i can't pase here..If any query on above explanation do reply here i will clarify..

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert

Hi

Can any one correct me on the above script..

Regards Vineeth.K
0 Kudos