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...
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
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
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.
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