Hey guys I am writing a script to move some vm's from one folder to another I have tried a couple of different ways but keep getting the same error. script is as follows:
$folder = Get-Folder -ID "Folder-group-v3166"
*
Move-Inventory -Item $vm -Destination $folder
Cannot bind parameter 'Item'. Cannot convert value "testvm" to type "VMware.VimAutomation.Types.VIObject". Error: "Invalid cast from 'System.String' to 'VMware.VimAutomation.Types.VIObject'."
At :line:29 char:20
+ Move-Inventory -Item <<<< $vm -Destination $folder
I have also tried this the same way as the example in the VI tookit help file with the same error :
#Move-Inventory -Item $vm -Destination (Get-Folder -ID "Folder-group-v3166")
This gets the same errror as above.
$vm is read in from a read-host but I have also tried subbing this with just a vm name and it makes no difference.
Any help would be great thanks!
Packetboy.
*
From what you described it seems that in the $vm variable you keep a string. But the cmdlet expects an object. In order to get that object you'll need to use the corresponding Get- cmdlet (in this case Get-VM). Here are some ways to achieve what you need:
$vm = Get-VM $vmName
$folder = Get-Folder -ID "Folder-group-v3166"
Move-Inventory -Item $vm -Destination $folder
Move-Inventory -Item (Get-VM $vmName) -Destination (Get-Folder -ID "Folder-group-v3166")
Move-VM -VM $vmName -Destination (Get-Folder -ID "Folder-group-v3166")
In all three cases in $vmName variable you keep the name of the VM that you want to move (which can be read from Read-Host).
Regards,
Dimitar
From what you described it seems that in the $vm variable you keep a string. But the cmdlet expects an object. In order to get that object you'll need to use the corresponding Get- cmdlet (in this case Get-VM). Here are some ways to achieve what you need:
$vm = Get-VM $vmName
$folder = Get-Folder -ID "Folder-group-v3166"
Move-Inventory -Item $vm -Destination $folder
Move-Inventory -Item (Get-VM $vmName) -Destination (Get-Folder -ID "Folder-group-v3166")
Move-VM -VM $vmName -Destination (Get-Folder -ID "Folder-group-v3166")
In all three cases in $vmName variable you keep the name of the VM that you want to move (which can be read from Read-Host).
Regards,
Dimitar
Thanks mate! That was it.. i am still pretty new to powershell so i guess this was a rookie mistake its all working now great
Thanks again.
Packetboy.