PeetersOnline.nl
Another way to gather VMware disk info with Powershell
I’ve created another way to gather and display VMware Virtual Disk information with the Powershell VI Toolkit.
The attached script generates a csv-file with all Virtual Machines’ Disks, in which Datastore they are stored, the LUN IDs of the extents that make up this Datastore (in HEX) and the Vendor of the SAN those LUNs are on (just in case you have multiple). Simpy a great way to determine which LUNs are used by which virtual server(s) in a complex environment.
By the way: the script is filled with comments to allow you to learn how it works.
create-vmdiskoverview (Rename to .ps1)
Enjoy!
Hugo
28 Responses to Another way to gather VMware disk info with Powershell
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008






[...] Hugo just posted a follow up to his original blog. This new script creates a CSV file, which can be imported in to Excel for [...]
Hi Hugo,
I’d like to a row for hostname but i’m not very smart in powershell, may you help me ?
Anyway, your script is very cool
Thx
@NiTRo
NiTRo,
Adjust the following line:
Select VM, Description, Disk, Datastore, hexLUN0, hexLUN1, hexLUN2, hexLUN3, SAN # Create output object
Replace it with this:
Select VMHost, VM, Description, Disk, Datastore, hexLUN0, hexLUN1, hexLUN2, hexLUN3, SAN # Create output object
And add the following line below it:
$myObj.VMHost = $VMHost.Name # ESX Server Name
Thanks,
Hugo
Thanks Hugo, it works like a charm !
I also wish i can get a field value from the VC, do you know if it is possible ?
Thanks
[...] 9, 2009 Another way to gather VMware disk info with Powershell: [...]
great information! thanks!
http://www.vmwarescripting.com/
[...] au script Powershell d’Hugo de PeetersOnline.nl, vous pourrez générer un fichier csv contenant la liste des VM [...]
Is there a way to modify this so that it would pull back sizes of the disks as well?
@David
@David
Easy! Just modify this line:
Select VM, Description, Disk, Datastore, hexLUN0, hexLUN1, hexLUN2, hexLUN3, SAN # Create output object
Change it into this:
Select VM, Description, Disk, DiskSizeGB, Datastore, hexLUN0, hexLUN1, hexLUN2, hexLUN3, SAN # Create output object
And add this line below it:
$myObj.DiskSizeGB = [math]::Round(($DISK.CapacityKB * 1KB / 1GB),0) #Disk Size
Hugo
@Hugo
Thank you Hugo. This was a big help.
Is there any way for RDMs to show up as RDMs? I noticed they show up as virtual disks on the datastore in which the mapping file exists. Wondering if there’s a way to dive deeper, and identify these as RDMs and indicate LUN ID. Also, any good resources for VI-Toolkit education? Been googling, but resources are limited. Thanks.
Hugo,
This script is great. It gives me almost everything I need… there is one thing I would like. I would like to add a column for the name of the VMDK as well. Being a newbie at scripting… is that possible?
@Eric
Modify this line:
Select VM, Description, Disk, Datastore, hexLUN0, hexLUN1, hexLUN2, hexLUN3, SAN # Create output object
into:
Select VM, Description, Disk, Datastore, VMDK, hexLUN0, hexLUN1, hexLUN2, hexLUN3, SAN # Create output object
Add the following line below that line:
$myObj.VMDK = $DISK.Filename.Split(“/”)[1]
Going off of the Question from Hugo on 1/27, is there a way to give the “used” space of the guest’s VMDK? I’m trying to monitor the growth on a differential disk of link-cloned VDI guests.
Hugo,
Great script, thank you. But when I run it scripts runs for number of minutes and than I got
————————–
You cannot call a method on a null-valued expression.
At :line:29 char:41
+ $myObj.Datastore = $DISK.Filename.Split <<<< (“[]“)[1] # Datastore Name
————————–
and no csv file is created.
@invisible I’m guessing you have $ErrorActionPreference set to “Stop”. Try setting: $ErrorActionPreference = “Continue”. You will still see a lot of errors, but the script will finish.
The reason for this script to generate errors, is that is assumes three disks are present in each and eveny vm. I had to pick a number and keep it the same for all the vm’s, because of difficulties displaying irregular information. Anyway, let me know if this helps.
Hugo
This script is very useful. I how do you change the number of present disks that the script scans for from 3 to 4? We have various VMs with more than 3 virtual disks. Thanks!
@Harm
The script does loop through ALL your disks. Only problem if you have more than 4 extents in a datastore. Then you should add hexLUN… to the following line:
Modify line:
Select VM, Description, Disk, Datastore, hexLUN0, hexLUN1, hexLUN2, hexLUN3, SAN # Create output object
Into: Select VM, Description, Disk, Datastore, hexLUN0, hexLUN1, hexLUN2, hexLUN3, hexLUN4, SAN # Create output object
Etc.
Hugo
Hi Hugo,
firstly, a great script! Can I also add a column for the datacenter? I am also new with powershell and scripting in general and I didn’t find anything about $myObj.* and the “Select” part in your script.
Thanks.
@Michael
I use “$myObj = “” | Select Name, Etc” to create custom objects to hold the output of my scripts. Read more here: http://www.peetersonline.nl/?s=advice
You could add an outer loop doing ForEach ($Datacenter in Get-datacenter){…} and add a property named $myObj.Datacenter with the value $Datacenter.Name.
Read some of the scripts on my site to get some feeling on how this works.
Hugo
Hi Hugo,
I also wish I can get a field value from the Disk path or disk drive letter, do you know if it is possible ?
Thanks
@Ejire
Try this script:
http://www.peetersonline.nl/index.php/vmware/get-vmware-disk-usage-with-powershell/
Hi Hugo,
Your script helped me a lot.
Thanks for sharing.
That’s great, thanks for commenting!
Hugo
Hi Hugo,
Could you give me an example of an outer loop to get the cluster that each VM is connected to. For some reason my loop doesn’t end.
Thanks!
Great post, I was trying to write my own script to do just this.
Thanks.
Script ran and listed the VMs but the hexLUN0 field = 0 for all vm’s and the rest of the hexLUN# fields are blank. The disks that aren’t listing properly are physical compatibility mode RDM drives….
Any ideas?