1. Export the complete folder structure with VM details of a datacenter from VC1 to a outputfile.
2. Then in VC2 i need to create only a particular folder with all its its sub-folders from the output file generated from VC1. This folder will be a root folder which is directly under datacenter in VC1.
3. After creating the particular folder structure, the script should read the vm's that was present in that folder & subfolder from output file and then it should search the same VM's in VC2 and place them into the folders identically.
The folder1 structure hs been taken from VC1 and has been created in VC2 with all the subfolders and placing the same VM's in the folders.
Not sure if I understood your point 2) but here are 2 scripts that should do what I think you want to do.
Export the VMs and the folderstructure.
The script uses a New-VIProperty to fetch the blue folderpath for a VM.
Import the folder structure and move existing VMs.
The complete folder structure that was exported will now be imported in datacenter MyNewDC under the folder Folder1.
Thanks Alan. That book is a marvellous work! Adopted many of them for my daily work.
That is correct, these scripts are VM-based.
To export/import also your empty folders, I suggest you use the Export-Folders and Import-Folders functions that come with the book module.
Luc, i accessed the sybex download page http://spa.sybex.com/WileyCDA/SybexTitle/VMware-vSphere-PowerCLI-Reference-Automating-vSphere-Administration.productCd-0470890797,navId-290600,pageCd-resources.html and downloaded Ch01 sample code.
I used Export-folders, Export-vmlocation, Import-folders, Import-vmlocation functions.
I altered this line to the one given below and i was able to accomplish the task without any problem.
Did that original line produce error messages ?
And how did the path look when it gave errors ?
I exported the folders and VM using export functions. And i want to import only one folder and subfolders and it's vm's in the target VC's. So i altered the output folder file and created the folders. And while hadling the VM location output file i made a mistake.
Sorry for that! Your function works perfect!
This post is Old! Any news to migrate folder and structure in to vcenters?
Any software or script do make this??
This script works a treat, I'm just wondering if it's possible to import my folder structure to the root of the DC rather than a temp folder (moving them manually won't exactly be difficult, but just wondering if it's possible).
How can I also script import of Yellow folders? Not that I have many of them, would be easy enough to remake them manually.
If you change the line that sets up the start folder like this, it should import in the root folder.
That almost worked, it imported to the root folder but to the root folder of the VC... Not under the datacenter that has been configured. Any advice?
Not sure I get the question, when you import to the folder Datacenters, that should create the folders in the root of the vCenter.
Perhaps you can add some screenshots to indicate what you mean ?
Note: The script imported all sub-folders correctly, I created the above screenshot manually as I deleted the folders after the script failed to create the above folder structure.
Create VM Folder Structure and Set Permissions?