VMware Cloud Community
Sam30
Enthusiast
Enthusiast

Copy-Harddisk error

When I copy all the hard disks of VM named "1", it copies all the disk to destination folder named "2" in datastore named "Data", the below command works:-


Get-HardDisk -VM 1 | Copy-HardDisk "[Data] 2/"


BUT


When I try to copy only one particular Disk it errors out as below :-


Get-HardDisk -VM 1 | Copy-HardDisk -HardDisk "[Data] 1/1.vmdk" -DestinationPath "[Data] 2/"

Copy-HardDisk : Cannot bind parameter 'HardDisk'. Cannot convert the "[Data] 1/1.vmdk" value of type "System.String" to type

"VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.HardDisk".

At line:1 char:46

+ Get-HardDisk -VM 1 | Copy-HardDisk -HardDisk "[Data] 1/1.vmdk" -DestinationPath  ...

+                                              ~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Copy-HardDisk], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyHardDisk


Any help, thanks

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try like this.

The Copy-HardDisk cmdlet expects a HardDisk object, not a string, on the HardDisk parameter.

Get-HardDisk -VM 1 |

where{$_.FileName -match "[Data] 1/1.vmdk"} |

Copy-HardDisk -DestinationPath "[Data] 2/"


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

0 Kudos