Folks,
I am trying to create a simple foreach loop for copying all VMDKs of a VM to its datastores including a "-bkp" name on it. The output of (Get-HardDisk -VM $vm | Select -ExpandProperty Filename) presents a VM with two VMDKs. The first VMDK is inside of the local datastore, and the second one is inside of the vm_os datastore. I have been trying to create a simple foreach loop to copy [local] OL55/OL55.vmdk to [local} OL55/OL55-bkp.vmdk, and the same for all subsequents VMDKs attached to a VM, but so far without any success.
It seems to be simple, but I got stuck! and need help from you guys.
Below is what I am trying to accomplish!
Get-HardDisk -VM $vm | Select -ExpandProperty Filename
[local] OL55/OL55.vmdk
[vm_os] OL55/OL55.vmdk
$vm = "OL55"
$vmdk = Get-HardDisk -VM $vm | Select -ExpandProperty Filename
ForEach ($hardisk in $vmdk)
{ Copy-HardDisk "[$vmdk]" -DestinationPath "[$vmdk-bkp]" }
Here is the output "error":
Copy-HardDisk : Cannot bind parameter 'HardDisk'. Cannot convert the "[[local] OL55/OL55.vmdk [vm_os] OL55/OL55.vmdk]" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.HardDisk".
At C:\Untitled5.ps1:14 char:16
+ { Copy-HardDisk <<<< "[$vmdk]" -DestinationPath "[$vmdk-bkp]" }
+ CategoryInfo : InvalidArgument: (:) [Copy-HardDisk], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyHardDisk
Copy-HardDisk : Cannot bind parameter 'HardDisk'. Cannot convert the "[[local] OL55/OL55.vmdk [vm_os] OL55/OL55.vmdk]" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.HardDisk".
At C:\Untitled5.ps1:14 char:16
+ { Copy-HardDisk <<<< "[$vmdk]" -DestinationPath "[$vmdk-bkp]" }
+ CategoryInfo : InvalidArgument: (:) [Copy-HardDisk], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyHardDisk
Any help is appreciated!!!
Thank you!