VMware Cloud Community
BostonTechGuy
Enthusiast
Enthusiast

Move VMs in Folders by FolderID

Hello,

I am curious if there is a way to move VMs into Folders using the FolderID.

Back Story

Reimporting a couple hundred VMs from Datastore migration.  The reimport is working great.  Since the company has a number of sub-level folders with the same name in the same cluster, we need to be sure the VMs go into the correct folder.

I have the FolderID that these VMs were in.  It would be excellent if I can just MOVE-VM using the FolderID.  I have tried a few simple scripts and they have failed.

I also reviewed this post: Re: I want to move VMs to a folder name called Linux, but we have multiple folder by the same name i...

I am assuming that would work in my case, it would be extremely impractical.  I was thinking maybe using a CSV file and with Folder and FolderID, do some sort of IF Statement.... Something like

Get-Folder -Name $_.Folder |

     If ($._ParentID -match $_.FolderID) ....

Something like that.. I cant get the syntex correct.  Plus not sure how to have it keep looking after second failure.. get it in some sort of loop.

Thanks

Boston Tech Guy

0 Kudos
1 Reply
markdjones82
Expert
Expert

How about this, haven't tested it so I would test first.

csv headers

vmname,folderid

$vmlist = import-csv vm_placement.csv

$vmlist | % {

$folder = Get-Folder -id $vmlist.folderid

Move-VM -VM $vmlist.vmname -destination $folder

}

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos