More

VMware PowerCLI – Get All Thick Provisioned Disks #2

By Antti Hurme 17/05/2013 4 Comments 1 Min Read

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
Written By

Who am I? | Linkedin

View All Articles
V
v
4 Comments
  1. christoph says:

    great script! Although we have a really big virtual environment with several hundred VMs and at least a dozen clusters it delivered the result within a few seconds. Thank you!

    1. Antti Hurme says:

      Happy to hear you found it useful :)

  2. Qasim says:

    Hi,

    Thanks for the script. Could you please help me sending output of this in an email?

  3. Adi Feldgajer says:

    Antti, As version 3 for this: Could you add the cluster and datastore for each vm.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.