Created
February 18, 2014 11:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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