[英]How to move a VM within VMs and Templates view using PowerCLI?
I am reorganizing the Host and Clusters and VMs and Templates in vCenter. 我要在vCenter中重新组织主机和群集以及VM和模板。 I want to do this automatically using a script.
我想使用脚本自动执行此操作。 I can move the VMs out of resource pools and into new ones no problem using the Move-VM command, however I also need to move the VMs into new folders in the VMs and Templates view as well.
我可以使用Move-VM命令将VM从资源池移出并移到新池中,但是我还需要将VM移入VMs和Templates视图中的新文件夹中。 I can create the folder I want to move it to using this command:
我可以使用以下命令创建要移动到的文件夹:
$newVMFolder = (Get-View (Get-View -ViewType Datacenter -Filter @{"name"=$vmFolderLocation}).vmfolder).CreateFolder($newFolderName)
Then when I use this command: 然后,当我使用此命令时:
Move-VM -VM $vm -Destination $newVMFolder
I get this error, 'Cannot convert the "Folder-group-..." value of type "VMware.Vim.ManagedObjectReference" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.VIContainer".' 我收到此错误,“无法将类型“ VMware.Vim.ManagedObjectReference”的“ Folder-group -...”值转换为类型“ VMware.VimAutomation.ViCore.Types.V1.Inventory.VIContainer”。
Any help would be much appreciated. 任何帮助将非常感激。
There might be an easier way to create a folder in the VM and Templates view than above, but I just added: 在VM和Templates视图中,可能有一种比上面更简单的方法来创建文件夹,但我只是添加了以下内容:
$newVMFolder = Get-Folder -Name $newFolderName -Type VM
after I create the folder. 创建文件夹后。
Now $newVMFolder is an inventory type instead of a managed object so 现在$ newVMFolder是库存类型而不是托管对象,因此
Move-VM -VM $vm -Destination $newVMFolder
now moves it into that folder. 现在将其移至该文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.