VMware Cloud Community
utarion
Contributor
Contributor
Jump to solution

How to determine if a disk is Thin

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
utarion
Contributor
Contributor
Jump to solution

Thank you very much that is perfect

0 Kudos
sdog
Contributor
Contributor
Jump to solution

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

0 Kudos
tonygent
Enthusiast
Enthusiast
Jump to solution

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 Smiley Happy

TG

0 Kudos
admin
Immortal
Immortal
Jump to solution

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]

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Confirmed, the StorageFormat property will tell you what kind of disk it is.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos