This script will display the VM partition information of all the Virtual Machines (both Linux and Windows) in vCenter.
PS> ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}
<output not shown>
-------------------------------------------------------------------------------------------------------------------------------------------------------
This modified version of above script will display the VM partition information of the Virtual Machines that are hosted on ESXi host : "iss-esxi-vm01.xxxx.com"
PS> ForEach ($VM in get-vmhost iss-esxi-vm01.xxxx.com | get-vm){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}
PS> ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}
<output not shown>
-------------------------------------------------------------------------------------------------------------------------------------------------------
This modified version of above script will display the VM partition information of the Virtual Machines that are hosted on ESXi host : "iss-esxi-vm01.xxxx.com"
PS> ForEach ($VM in get-vmhost iss-esxi-vm01.xxxx.com | get-vm){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}
Name : itc-esxi-dnx01.xxxx.com
DiskPath : C:\
Capacity(MB) : 51191
Free Space(MB) : 36503
Free Space % : 71
Name : iss-esxi-mail1.xxxx.com
DiskPath : /
Capacity(MB) : 1008
Free Space(MB) : 813
Free Space % : 81
Name : iss-esxi-mail1.xxxx.com
DiskPath : /boot
Capacity(MB) : 99
Free Space(MB) : 86
Free Space % : 87
Name : iss-esxi-mail1.xxxx.com
DiskPath : /tmp
Capacity(MB) : 1008
Free Space(MB) : 975
Free Space % : 97
<output truncated>
Hi! Raj, greate script!
ReplyDeleteI,m not greate specialist in powershell & powercli :(
Can you help me, how add in your script exporting results in *.csv file, please?
Hi Thanks for your scripting it's very use full for me..
ReplyDelete