简体   繁体   English

如何使用PowerCLI在VM和模板视图中移动VM?

[英]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.

相关问题 如何使用powercli并行移动多个VM? - How can I move multiple VMs in parallel using powercli? 如何在Horizo​​n View PowerCLI中创建新的VM? - How to create new VMs in Horizon View PowerCLI? 如何使用PowerShell(PowerCLI)确定VM自定义规范状态? - How to determine a VMs customization specification state with PowerShell (PowerCLI)? 如何在PowerCLI中快速找到具有串行端口的VM - How can I quickly find VMs with serial ports in PowerCLI powercli 可以告诉我列出虚拟机的网络适配器时虚拟机名称是什么吗? - Can powercli tell me what the VM Name is when listing network adapters for vms? 如何使用PowerCli以逗号分隔的字符串输出VM guest虚拟机硬盘信息 - How to output VM Guest Hard Disk information in comma separated string using PowerCli 我在 azure 中有 4 个 vms 如何使用 powershell 将一个 vm 通信到另一个 vm? - i have 4 vms in azure how to communicate the one vm to another vm using powershell? 使用PowerCLI重新启动后是否最好等待确保VM备份? - Best wait to ensure VM is back up after restart using PowerCLI? 使用powercli在esxi内部部署的vm上启用ssh服务 - enable ssh service on vm deployed inside esxi using powercli 如何通过powercli检索VM的名称和路径 - How to retrieve the name and path of VM's through powercli
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM