Skip to content

Instantly share code, notes, and snippets.

@BenNeise
Created February 18, 2014 11:59
Show Gist options
  • Save BenNeise/9069627 to your computer and use it in GitHub Desktop.
Save BenNeise/9069627 to your computer and use it in GitHub Desktop.
Uses vSphere PowerCLI to display disk information. Most importantly, whether or not the disk is ThinProvisioned.
# Create an empty array for results
$arrResults = @()
# Get the .net view of the virtual machines
$objVMViews = Get-View -ViewType "VirtualMachine" | Where-Object {!$_.Config.Template}
# Loop through the .net view objects representing the machines
ForEach ($objVMView in $objVMViews){
# Loop through the .net view's devices
ForEach ($objDevice in $objVMView.Config.Hardware.Device) {
# Where the device is a virtual disk
If ($objDevice.GetType().Name -eq "VirtualDisk"){
# Create a new object to represent the virtual disk
$objVirtualDisk = New-Object PSObject
# Append properties to the disk object based on the view object
$objVirtualDisk | Add-Member -Name "Name" -MemberType NoteProperty -Value $objVMView.Name
$objVirtualDisk | Add-Member -Name "DeviceLabel" -MemberType NoteProperty -Value $objDevice.DeviceInfo.Label
$objVirtualDisk | Add-Member -Name "FileName" -MemberType NoteProperty -Value $objDevice.Backing.FileName
$objVirtualDisk | Add-Member -Name "DiskMode" -MemberType NoteProperty -Value $objDevice.Backing.DiskMode
$objVirtualDisk | Add-Member -Name "SizeGB" -MemberType NoteProperty -Value ($objDevice.CapacityInKB / 1024 / 1024)
# If there is a ThinProvisioned property, then the disk is sparse
If ($objDevice.Backing.ThinProvisioned){
$objVirtualDisk | Add-Member -Name "ThinProvisioned" -MemberType NoteProperty -Value $True}
Else {
$objVirtualDisk | Add-Member -Name "ThinProvisioned" -MemberType NoteProperty -Value $False
}
# Append the virtual disk object to the array of results
$arrResults += $objVirtualDisk
}
}
}
# Display the results on screen
$arrResults | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment