I have a quick query. I am trying to determine using Powershell if a Disk is thin provisioned or not. Is there a way programmatically to determine this? I was using the following but it does not provide me with what I want.
$fileQueryFlags = New-Object VMware.Vim.FileQueryFlags
$fileQueryFlags.FileType = $true
$fileQueryFlags.FileSize = $true
$fileQueryFlags.Modification = $true
Thanks
That info is available in the VirtualDiskFlatVer2BackingInfo object in the thinProvisioned property.
The following script scans through all your VMs and all their devices and will list any thin provisioned disks.
Get-VM | Get-View | % { Write-Host $_.Name foreach($dev in $vm.config.hardware.Device){ if($dev.GetType().Name -eq "VirtualDisk"){ if($dev.Backing.ThinProvisioned){ Write-Host "`t" $dev.DeviceInfo.Label "ThinProvisioned" } } } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That info is available in the VirtualDiskFlatVer2BackingInfo object in the thinProvisioned property.
The following script scans through all your VMs and all their devices and will list any thin provisioned disks.
Get-VM | Get-View | % { Write-Host $_.Name foreach($dev in $vm.config.hardware.Device){ if($dev.GetType().Name -eq "VirtualDisk"){ if($dev.Backing.ThinProvisioned){ Write-Host "`t" $dev.DeviceInfo.Label "ThinProvisioned" } } } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much that is perfect
I get this error.
You cannot call a method on a null-valued expression.
At C:\thin_query.ps1:4 char:18
+ if($dev.GetType <<<< ().Name -eq "VirtualDisk"){
I have vCenter Server 4.0 update 1.
Any suggestions?
Regards
Looks like a Cut and Paste issue 🐵
try replacing the $vm with $_ as below :
Write-Host $_.Name
foreach($dev in $_.config.hardware.Device)
Let me know if this works for you
TG
Actually I believe that starting with PowerCLI 4.0 U1 Get-HardDisk will tell you if a disk is thin or not. I'm away from my lab at the moment so I can't confirm but I'm pretty sure we made this change.
=====
Carter Shanklin
Read the PowerCLI Blog
[Follow me on Twitter|http://twitter.com/cshanklin]
Confirmed, the StorageFormat property will tell you what kind of disk it is.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference