VMware PowerCLI – Get All Thick Provisioned Disks #2

Posted on 17/05/2013 · Posted in Development, VMware

Las time I found a nice script that allowed to get all thick provisioned disks and listed them out. The script utilized the get-vm commandlet that isn’t exactly effective and is quite slow. Unforionately I managed to delete the commends while fiddling with the database from that post and thus lost the suggestion fromt he commends. Here’s my second take on the problem and is a lot faster than the previous one. Also the output is better this time around.

 

#############################################################
###
### Get all thick provisioned disks v2
### Version 1
### 17.5.2013
###
##############################################################
###
### CONFIGURATION
###
$login_user = ""
$login_pwd = ""
$login_host = "Enter your vCenter Server here"
##############################################################
### END
##############################################################
###Prepare variables
$vmlist = @()

###Check if we are connected to vCenter Server(s)
if($global:DefaultVIServers.Count -lt 1)
{
	echo "We need to connect first"
	#To connect using predefined username-password
	#Connect-VIServer $login_host -User $login_user -Password $login_pwd -AllLinked:$true

	#To connect using PowerCLI credential store
	Connect-VIServer $login_host -AllLinked:$true
}
else
{
	echo "Already connected"
}

get-view -ViewType VirtualMachine -Property Name, "Config.Hardware.Device" | %{
	$vmName = $_.name
	$_.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualDisk"} | %{
		if(!$_.Backing.ThinProvisioned){
			$sizeInGb = [Math]::Round(($_.CapacityInKB / 1MB),2)
			$type = if ($_.Backing.ThinProvisioned) { “THIN” } else { "THICK" }
			$label = $_.DeviceInfo.Label
			$vmlist += "" | Select-Object @{n="VmName";e={$vmName}},@{n="DiskLabel";e={$label}},@{n="Backing";e={$type}},@{n="SizeInGB";e={$sizeInGb}}
		}
	}
}
#Print out our table
$vmlist | format-table -autosize