1 Reply Latest reply on May 24, 2011 9:02 PM by mattboren

    Remove-HardDisk Syntax Help




      I am attempting to delete a specific harddisk using the Remove-HardDisk cmdlet in powercli and cannot seem to figure out the correct syntax.  At the link below it states that with the -HardDisks perameter you can specify the hard disks you want to remove.  However I get an error when attempting to issue the syntax below which return "Cannot bind perameter 'HardDisk. Cannot convert the value."  Any information would be greatly appreciated, unfortunately VMware deosn't have any good examples on the Cmdlet Reference Site.


      Get-HardDisk -VM $vmname | Remove-HardDisk -HardDisk "Hard disk 1" - DeletePermanently

      Get-HardDisk -VM $vmname | Remove-HardDisk -HardDisk "[Datastore] vmname/vmname.vmdk" - DeletePermanently






        • 1. Re: Remove-HardDisk Syntax Help
          mattboren Master

          Hello, THEL1ZARDKING-


          You were pretty close.  I wrote a couple of examples that utilize the different parameters in different ways, to try to illustrate their usage.  Here are a few ways that should work:


          ## remove a harddisk based on its "name" according to the VM, such as "Hard disk 1" or "Hard disk 2"
          Get-HardDisk -VM $strVMName | ?{$_.Name -eq "Hard disk 1"} | Remove-HardDisk -DeletePermanently

          ## a variation, again based on the disk's "name"
          Remove-HardDisk -DeletePermanently -HardDisk (Get-HardDisk -VM $strVMName | ?{$_.Name -eq "Hard disk 1"})

          ## remove a harddisk based on its datastore path
          Get-HardDisk -Datastore "Datastore" -DatastorePath "[Datastore] VMName/VMName.vmdk" | Remove-HardDisk -DeletePermanently


          You first line just needed a bit of tweaking, to either the first or second example above.  Your second line could be changed a bit, either to be like the second or third example above.  The key is passing a HardDisk VI object to Remove-HardDisk, either via the pipeline (ex. 1 and 3), or explicitly (ex. 2).


          How do those do for you?