# How to move existing vm to specific folder in vcenter

**URL:** <https://forum.ansible.com/t/how-to-move-existing-vm-to-specific-folder-in-vcenter/27838>\
**Category:** Ansible Project\
**Created:** [June 21, 2018, 3:44am UTC](https://forum.ansible.com/t/how-to-move-existing-vm-to-specific-folder-in-vcenter/27838 "2018-06-21T03:44:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![llmiell\_Sanimzz](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@llmiell\_Sanimzz](https://forum.ansible.com/u/llmiell_Sanimzz)\
**Post date:** [June 21, 2018, 3:44am UTC](https://forum.ansible.com/t/how-to-move-existing-vm-to-specific-folder-in-vcenter/27838/1 "2018-06-21T03:44:58Z")

</div>

Hi,

I need to move VM to another folder,but vmware\_guest could not support this.  
Could you help on this?

Thanks,

---

<div class="post-metadata">

**Author:** ![Sebastien\_Desbois](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@Sebastien\_Desbois](https://forum.ansible.com/u/Sebastien_Desbois)\
**Post date:** [June 22, 2018, 9:28am UTC](https://forum.ansible.com/t/how-to-move-existing-vm-to-specific-folder-in-vcenter/27838/2 "2018-06-22T09:28:35Z")

</div>

Best way to do this for the moment is to have ansible executing an powercli script

Example path given to the script : Test-Env/Linux/ProjectA

Powercli script :

`  
$Separator = ‘/’

#Powercli don’t know how to handle a full path for a fodler… Need to artificialy get the end folder…  
$root = Get-Datacenter  
$root = Get-Inventory -Name “vm” -Location $root -NoRecursion  
$Folderpath.Split($Separator) | %{  
if((Get-Inventory -Location $root -NoRecursion | Select -ExpandProperty Name) -contains “vm”){  
$root = Get-Inventory -Name “vm” -Location $root -NoRecursion }  
else {  
$root = Get-Inventory -Name $\_ -Location $root -NoRecursion }  
}

$EndFolder = $root | where {$\_ -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl]}|%{  
Get-Folder -Name $\_.Name -Location $root.Parent -NoRecursion }

#Move the VM to the correct folder  
Move-VM -VM $VM -InventoryLocation $EndFolder  
`

If you have several datacenters in your VMware inventory, need to pass it as parameter also and change the code to

`$root = Get-Datacenter "MyDatacenter"`
