VMware Cloud Community
slashji
Contributor
Contributor
Jump to solution

Find Thick provisioned disks and shutdown then delete whole VM

I need to find all VM´s with Thick Provisioned Disk(s) and delete them. 

At the moment i can get the list of VM´s using Thick provisioned disks using command:

Get-Datastore | Get-VM | Get-HardDisk | Where {$_.storageformat -eq "Thick" } | Select Parent, Name, CapacityGB, storageformat 

 

Now i still cant understand how can i pipe the Stop-VM and then Remove-VM -DeletePermanently command into the previous one.

I feel like its really simple oneliner but im missing something out in the basics of PowerShell...

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could use a Where-clause.

Get-Datastore | Get-VM | 
Where{Get-HardDisk -VM $_ | where{$_.StorageFormat -eq 'Thick'}} |
Stop-VM -Confirm:$false |
Remove-VM -DeletePermanently -Confirm:$false


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

You could use a Where-clause.

Get-Datastore | Get-VM | 
Where{Get-HardDisk -VM $_ | where{$_.StorageFormat -eq 'Thick'}} |
Stop-VM -Confirm:$false |
Remove-VM -DeletePermanently -Confirm:$false


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

Reply
0 Kudos
slashji
Contributor
Contributor
Jump to solution

Perfect, thanks!
Little note that Stop-VM and Remove-VM have to be run as separate tasks since Remove-VM is using info piped from Stop-VM in your example.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That was the intention.
Stop-VM returns a VirtualMachine object, which is then used by Remove-VM.
Isn't that working?


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

Reply
0 Kudos