I wanted to know how many disks in our environment are thin provisioned, so I wrote a quick function to export that list to a CSV file.
I have it pull the VM name, vmdk path & name, Size in GB, and if it’s Thin Provisioned (Boolean, which should always be true).
Just copy & paste this into a .ps1 file and run it (or download link at bottom). The initial instantiation of $vms takes a while, depending on the size of your environment, but the rest goes quickly. Make sure you’re connected to a host or vcenter before you run it, or you won’t get anything.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
function find-thin{ write-host -fore green `n "getting all VMs, this may take a while" $vms = get-vm |sort name | get-view Write-host -fore green `n "Starting Scan" $vmdks = @() foreach ($vm in $vms){ foreach ($device in $vm.config.hardware.Device){ if($device.GetType().Name -eq "VirtualDisk"){ if($device.Backing.ThinProvisioned){ $info = "" | Select VM, File, SizeInGB, Thin $info.VM = $vm.name $info.File = $device.backing.filename $info.SizeInGB = $device.capacityinkb/1048576 $info.thin = $device.Backing.ThinProvisioned $vmdks += $info } } } } write-host -fore green `n "finished searching all VMs" `n $vmdks | export-csv d:\thindisk.csv } find-thin |
To change where the file is saved, simply change the path in line 27 to the destination of your choice.
Download: find-thin.ps1
Great function..thanks!
Hi,
Nice one thanks for this.
How would you get the script to also list the Hard Disk # for each disk as well as the file path?
thanks
You are such a great guy!
Thanks