Friday, April 13, 2012

PowerCLI script for listing VM partition information

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)}})}

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>

2 comments:

  1. Hi! Raj, greate script!
    I,m not greate specialist in powershell & powercli :(
    Can you help me, how add in your script exporting results in *.csv file, please?

    ReplyDelete
  2. Hi Thanks for your scripting it's very use full for me..

    ReplyDelete

Popular Posts

About Me

My photo
I have started this blog to share my work experience and spread some smart solutions on Linux to Internet community. I'm hoping more people will get benefited from this blog. Brief about me: I have 14+ years experience working as System Admin and currently work with VMware.