My question is in regards to removing a VHD using Remove-VMHardDiskDrive. What is the correct syntax for the -VMHardDiskDrive<HardDiskDrive[]> parameter? I tried the name, drive letter, and number, but none worked.
Here are the steps I used to create the drive in case that aids in resolving the issue.
I created a drive using New-VHD. I mounted it with Mount-VHD; Get-Disk shows it as Number 6. I partitioned it and assigned a drive letter (it shows as J) Then I used Format-Volume -DriveLetter J -FileSystem NTFS -Full -Force and that worked. Then I dismounted the drive, then connected the drive to a Linux guest in Hyper-V. I
I now want to remove the drive, but can't get the right syntax for Remove-VMHardDiskDrive. PowerShell keeps complaining about the VMHardDrive parameter:
PS C:\Windows\system32> Remove-VMHardDiskDrive -VMName CentOS_6.6_VM -VMHardDiskDrive MyDrive.vhdx -WhatIf
Remove-VMHardDiskDrive : Cannot bind parameter 'VMHardDiskDrive'. Cannot convert the "MyDrive.vhdx" value of type
"System.String" to type "Microsoft.HyperV.PowerShell.HardDiskDrive".
At line:1 char:63
+ Remove-VMHardDiskDrive -VMName CentOS_6.6_VM -VMHardDiskDrive MyDrive.vhdx -WhatIf
+
~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-VMHardDiskDrive], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.HyperV.PowerShell.Commands.RemoveVMHardDiskDriveCommand
Any help is appreciated.