WoodITWork.com

It's about time I let the world know what I was thinking...

Datastore and storage information from PowerCLI

Here are some PowerCLI single line scripts for getting some storage and datastore information: Find the Number of VMs on all Datastores

Get-Datastore | Sort-Object Name | Get-View | Format-Table @{Label="Datastore Name";Expression={$\_.Info.Name}}, @{Label="Number of VMs";Expression={$\_.VM.Length}}

Get VM Guest Disk Free Information

Get-VM | Where { $\_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskFreeMB";Expression={\[math\]::Round((($\_.FreeSpace)/1MB),2)}}

Get the 10 VM Guest disks with the least amount of free space

Get-VM | Where { $\_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskFreeMB";E={\[math\]::Round((($\_.FreeSpace)/1MB),2)}} | Sort DiskFreeMB | Select -First 10

Get combined size of each VMs Disks

Get-VM | select Name, @{ Name="Disks"; Expression={ ($\_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}

sorted by size

Get-VM | select Name, @{ Name="Disks"; Expression={ ($\_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }} | sort Disks -descending

Get Disk Path, Capacity, Free and Used space

Get-VM | Where { $\_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskCapacityGB";Expression={\[math\]::Round((($\_.Capacity)/1GB),2)}},@{Name="DiskUsedMB";Expression={\[math\]::Round((($\_.Capacity - $\_.FreeSpace)/1MB),2)}},@{Name="DiskFreeMB";Expression={\[math\]::Round((($\_.FreeSpace)/1MB),2)}}