VMware Cloud Community
paspot
Contributor
Contributor

PowerCli: Get thick provisioned disks for a selected group of VM

I'm trying to get all the Thick Provisioned disk from VMs running on specific hosts but the script doesn't work. Why?

Here's my short script which is not returning anything:

$vm=get-vm |where {$_.VMHost -like "xyz*"}

get-vm $vm |get-harddisk |where {$_.StorageFormat -eq "Thick"}

What is working:

"get-vm $vm |get-harddisk" works but it gives me all disks for that list of VM, Thin and Thick. That's not what I want.

"get-vm |get-harddisk |where {$_.StorageFormat -eq "Thick"}" also works but it gives me thick provisioned disks for ALL VMs. That's also not what I want.

Any idea what could be wrong? I know I have Thick disks in that list of VM so why is it not giving me anything when I use "where"?

0 Kudos
10 Replies
LucD
Leadership
Leadership

You can combine that in one pipeline construct

Something like

Get-VMHost -Name xyz* |

Get-VM |

Get-HardDisk |

where{$_.StorageFormat -eq 'Thick'} |

Select @{N='VM';E={$_.Parent.Name}},Name,StorageFormat

If you want the VMs which have Thick harddisks, you can package that in a Where-clause

Get-VMHost -Name xyz* |

Get-VM | where{Get-HardDisk -VM $_| where{$_.StorageFormat -eq 'Thick'}} |

Select Name


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

0 Kudos
paspot
Contributor
Contributor

It does not work. I tried on a vCenter 6.0 and vCenter 6.7 ans as soon as I use the "where{$_.StorageFormat -eq 'Thick'}" in combination with a specific list of VM, it stops working.

I managed to get what I need from RVTools but I woud like to know why I can't get it from Powershell.

0 Kudos
LucD
Leadership
Leadership

Can you show me how you run it?


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

0 Kudos
paspot
Contributor
Contributor

I used the following lines:

Get-VMHost -Name xyz* |Get-VM | Get-HardDisk | where{$_.StorageFormat -eq 'Thick'} |Select @{N='VM';E={$_.Parent.Name}},Name,StorageFormat

and

Get-VMHost -Name xyz* | Get-VM | where{Get-HardDisk -VM $_| where{$_.StorageFormat -eq 'Thick'}} | Select Name

Both commands does not give me anything. It should list me 132 thick provisioned disks. (or their parent VM for the second command)

I also made sure that "Get-VMHost -Name xyz*" was giving me the right set of hosts.

If I use "Get-VMHost |Get-VM | Get-HardDisk | where{$_.StorageFormat -eq 'Thick'} |Select @{N='VM';E={$_.Parent.Name}},Name,StorageFormat" without any filter for specific hosts, it works but I get the results for all VM.

Same thing for "Get-VMHost  | Get-VM | where{Get-HardDisk -VM $_| where{$_.StorageFormat -eq 'Thick'}} | Select Name" without any filter for specific hosts, I get a lists of all VMs with thick disks...

0 Kudos
LucD
Leadership
Leadership

And this returns a list of VMs of which some have a Thick harddisk?

Get-VMHost -Name xyz* | Get-VM

Just tried those first 2, and for me, they work correctly.

Are you copying this to the PS prompt or running it from a .ps1 file.


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

0 Kudos
paspot
Contributor
Contributor

"Get-VMHost -Name xyz* | Get-VM" gives me all VMs on those hosts.

I'm doing a copy/paste of the commands from notepad to the PS prompt. I created a .ps1 and doesn't work either.

I'm running this on "VMware PowerCLI 11.2.0 build 12483598". I also tried on older version "VMware PowerCLI 6.5 Release 1 build 4624819". Same result.

0 Kudos
LucD
Leadership
Leadership

The PowerCLI version shouldn't matter with such basic cmdlets.
I can't repeat what you are seeing, there must be something specific in the way you run the code or in your environment.

Did you stop/start your PS session between trial runs?


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

0 Kudos
LucD
Leadership
Leadership

Ultimately, could you make a screenshot of how you run this from the prompt?

Or attach the .ps1 file?


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

0 Kudos
paspot
Contributor
Contributor

I was able to make it work on a 3rd vCenter I use for tests. I don't know if it has anything to do with the problem but this one is running 6.7.0.42000 Build 15132721 where my other 2 vCenters are running on 6.7.0.40000 Build 14367737 and 6.0.0 Build 13638473.

I'll try again later once I upgrade my 2 vCenters to the latest version.

Thanks for you time!

0 Kudos
LucD
Leadership
Leadership

This is rather basic stuff.
Afaik this has nothing to do with the vCenter version.


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

0 Kudos