vSphere 6.5
I'd like to organize my VMs using folders named after business groups. Because we have multiple data centers, same folder name will appear more than once under vCenter. For example, a "IT" folder will appear at every data center. Because of the amount of VMs I need to move, I try to use PowerCLI to move them but I have a hard time telling it to move to the "IT" folder in the data center it's in.
PowerCLI C:\> Move-VM "it1" -Destination "IT"
Move-VM : 2/27/2019 4:28:59 PM Move-VM The specified parameter 'Destination' expects a single value, but your name criteria 'IT' corresponds to multiple values.
How do I make it recognize it's the "IT" folder in the data center the VM is in? I was trying to use Get-Folder to find the unique ID for the folder but I still can't tell which "IT" folder in the output is for the particular data center.
Thanks,
Try this great function by LucD as I've used it in situations like yours often. Also, FYI, in the future this sort of thing should go in the PowerCLI sub-forum (where you're likely to be helped by Luc directly).
Use the -Location flag to specify the parent folder.
Hi daphnissov,
Thanks for the prompt reply. I am not sure what you meant by -location flag which I don't see in the Move-VM cmdlet as an option. All these folders' parents are 'vm'.
PowerCLI C:\> Get-Folder -Name "IT*" | Select-Object name,id,Parent
Name Id Parent
---- -- ------
ITC Folder-group-v14939 vm
ITC Folder-group-v14940 vm
ITC Folder-group-v14941 vm
ITAP Folder-group-v15324 vm
ITAP Folder-group-v15327 vm
ITC Folder-group-v16109 vm
I was hoping to pass the "Id" value to Move-VM's -Destination argument but it does not accept it.
Move-VM : 2/27/2019 6:00:00 PM Move-VM | Could not find VIContainer with name 'Folder-group-v14941'. |
thanks,
What version of PowerCLI do you have installed?
Hi daphnissov,
PowerCLI C:\> Get-PowerCLIVersion
PowerCLI Version
----------------
VMware PowerCLI 6.5 Release 1 build 4624819
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component 6.5 build 4624453
VMware VimAutomation Core PowerCLI Component 6.5 build 4624450
VMWare ImageBuilder PowerCLI Component 6.5 build 4561891
VMWare AutoDeploy PowerCLI Component 6.5 build 4561891
VMware Vds PowerCLI Component 6.5 build 4624695
VMware Cloud PowerCLI Component 6.5 build 4624821
VMware HA PowerCLI Component 6.0 build 4525225
VMware HorizonView PowerCLI Component 7.0.2 build 4596620
VMware Licensing PowerCLI Component 6.5 build 4624822
VMware PCloud PowerCLI Component 6.5 build 4624825
VMware Storage PowerCLI Component 6.5 build 4624820
VMware vROps PowerCLI Component 6.5 build 4624824
VMware vSphere Update Manager PowerCLI 6.5 build 4540462
Thanks,
I've updated PowerCLI to the latest. Now Move-VM has
[-InventoryLocation <FolderContainer>]
However, I still can't find a way to uniquely identify the folder I want to move to because there are more than one folder with the same name at different datacenters.
Try this great function by LucD as I've used it in situations like yours often. Also, FYI, in the future this sort of thing should go in the PowerCLI sub-forum (where you're likely to be helped by Luc directly).
I am sure the proposed solution would work but I've decided to rename the folders with the same name. Not sure why it's not built-in to have an easy way to specify a folder regardless how unique its name is.
Thanks,