VMware Cloud Community
mgraveney
Contributor
Contributor

Query about Remove-HardDisk cmdlet

Trying to use powershell to remove a 2nd hard disk and seem to be having trouble

Param($VMname)
Get-HardDisk -VM $VMname | Remove-HardDisk -HardDisk "Hard Disk 2" -DeletePermanently

If i run without the "-HardDisk "Hard Disk 2" -DeletePermanently" it interactivley allows me iterate and remove I would however like to specify the correct disk.

Anyone know where I'm going wrong with the syntax?

Thanks in advance

Tags (2)
0 Kudos
2 Replies
LucD
Leadership
Leadership

Try it like this

Get-HardDisk -VM $VMname | where {$_.Name -eq "Hard Disk 2"} | Remove-HardDisk -DeletePermanently


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

0 Kudos
mgraveney
Contributor
Contributor

Thanks worked a treat

0 Kudos