Quick VMWare inventory script
Posted in Powershell, VMWare
here is a little script i use to gather few informations from our VMWare farm. This snippet goal is to retrieve informations about CPU, Cores and disks in a variable in order to do some filtering on informations, to brainstorm about new solutions, specially storage solution.
I’ve find many scripts on the internet, but none of them where sexy in my opinion… So i decided to make mine and share it with you.
$Output = @() Get-View -SearchRoot (Get-Cluster '<datacenter>' | Get-View).MoRef -ViewType virtualmachine -Filter @{'Config.Template'='False'} | Select *, @{N="Disks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending Disks | % { $VM = $_ $prop = New-Object System.Collections.Specialized.OrderedDictionary $prop.add('Name',$VM.name) $prop.add('CPUSocket',$vm.config.hardware.NumCPU) $prop.add('CorePerSocket',$vm.config.hardware.NumCoresPerSocket) $Disk = 0 $TotalSize = 0 $VM.Guest.Disk | % { $prop.add("Disk$($Disk) Letter/Path",$_.DiskPath) $prop.add("Disk$($Disk) Capacity (GB)",[math]::Round($_.Capacity/ 1GB)) $prop.add("Disk$($Disk) FreeSpace (GB)",[math]::Round($_.FreeSpace / 1GB)) $TotalSize = $TotalSize + [math]::Round($_.Capacity/ 1GB) $Disk++ } $prop.add('TotalSize',$TotalSize) $Output += [PSCustomObject]$prop } $Output
You can find the script on Github.
Update: Thanks to Grzegorz Kulikowski hint, i’ve changed the line 2 to gain much more speed, and sexy š
Hi there, i think you can make it even more sexy š Replace this bit from line 2:
Get-Cluster ” | Get-VM | Get-View | Where {-not $_.Config.Template} |
With:
get-view -ViewType virtualmachine -Filter @{‘Config.Template’=’True’} |
Now that’s +50 to sexiness š and +999 to speed
if you want it really +999 to sexiness and +1337 to speed, you can use -property inside get-view.
Cheers !
Thanks for the hint and the chat on FB, i’ve changed the line n° 2 š