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
The intent of this blog is to share my work experience and spread some smart solutions on Linux to System Administrators. I'm hoping the solutions shared in this Blog would be helpful and come as a handy for Viewers. Brief about me: I have 18+ years work experience in System and Cloud Administration domain, primarily works on VMware Cloud Products (vSphere, vCloud Director, vRealize Automation, NSX Adv. Load Balancer, vROps).