Home > PowerCLI, Powershell > Datastore and storage information from PowerCLI

Datastore and storage information from PowerCLI

September 3rd, 2010

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)}}
Comments are closed.