VMware Cloud Community
charleswelton
Enthusiast
Enthusiast
Jump to solution

Automation to Migrate Folder Structure w/ Permissions to Another VCenter

Hello:

I'm in the process of automating complete host migration from VCenter running 5.5 to VCenter running 6.  I have already automated the move of the hosts, VMs, and networking.  I'm now trying to code the piece of migrating the folders with permissions.

Are there are specific cmdlets in PowerCLI that can help with this, or does anyone have any existing code that I could use?

Thank you!

Charles

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Found the issue in the function.

There was a NoRecursion switch missing on the 2nd call to Get-Folder.

I have updated the post.

Thanks for discovering this "feature" :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

There are a number of links in Re: Specifying cluster's location with multiple folders (same name, different hierarchy)

You'll find another one, for folders, in How to copy folders structure between two virtual center servers ?

And there are several examples in this community, do a search on migrate



Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
kermic
Expert
Expert
Jump to solution

You might also take a look at the Inventory Snapshot fling over here: https://labs.vmware.com/flings/inventorysnapshot

This thing connects to your source vCenter, queries the inventory and generates PowerCLI code that you can run against another (new) vCenter to recreate the inventory, including folder structures, roles and permissions.

Take a look at it's documentation, section VI.C., which specifically talks about your scenario.

You don't necessarily have to use it as-is / out of the box. You may as well just use it as a solution to generate the "alpha" version code for your modification.

I have recently used this fling to migrate from 5.1 vCenter on Windows to 6.0 VCSA. I guess it saved me a considerable amount of time.

Hope this helps.

0 Kudos
charleswelton
Enthusiast
Enthusiast
Jump to solution

Hi, LucD...

I ran into your "Get-FolderByPath" function, and it works for moving 99% of my VMs to their proper folder location.  However, there is a path returning more than one result, which causes the following error:

Move-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VIContainer'...

I thought "Get-FolderByPath" function would move VM into the exact folder I specified?  Is there a way to get around this?

Thanks for all your help as usual!

Charles

0 Kudos
charleswelton
Enthusiast
Enthusiast
Jump to solution

To add to my recent reply, here are the two paths that the "Get-FolderByPath" function finds:

ssh01/Test_Lab

ssh01/Apps/Test_Lab

... even though I am specifying "ssh01/Test_Lab" as the destination path.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just to verify, is 'ssh01' the name of a datacenter or a folder ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
charleswelton
Enthusiast
Enthusiast
Jump to solution

It is the name of the datacenter.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

When you call the Get-FolderByPath function, what did you pass on the Path parameter ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
charleswelton
Enthusiast
Enthusiast
Jump to solution

Hi, LucD...

Here is a code snippet:

get-content ${vmLocFile} | foreach {

  $VM = $_.ToString().split("`t")[0]

  $folderPath = $_.ToString().split("`t")[1]

  $folder = Get-FolderByPath -Path "${folderPath}"

  Write-Host $folder

  Write-Host (Get-Folder $folder | get-view).moref.value

  Get-VM -Name $VM | Move-VM -Destination $folder

  if ($? -eq "True")

  {

  Write-Host "Successfully moved ${VM} to proper folder!" -ForegroundColor "green"

  Write-Host " "

  } else {

  Write-Host "Failed to move ${VM} to proper folder!" -ForegroundColor "red"

  Write-Host " "

}

I'm looping through a tab delimited file that looks like the following:

testhostmove05ssh01/Special_Permissions/AppDev
testhostmove08ssh01/Test_Lab
testhostmove2ssh01/Infrastructure/CA
testhostmove07ssh01/Temporary_ssh01s
wdc-vtempgrdp01ssh01/zDR_Placeholders_WDC01/zDR_Apps
testhostmove04ssh01/Special_Permissions/Monitoring
testhostmove09ssh01/Apps/Websense
testhostmove10ssh01/Apps/WebServer_DMZ
testhostmove06ssh01/Special_Permissions/SCCM
testhostmove3ssh01/Infrastructure/CA/Monitoring/CATest/eHealth

Where the first column is the "VM" and the second column is the "full path".  I'm feeding the "Get-FolderByPath" function the full path.  As I mentioned, "ssh01" is the datacenter.

Thanks...

Charles

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Found the issue in the function.

There was a NoRecursion switch missing on the 2nd call to Get-Folder.

I have updated the post.

Thanks for discovering this "feature" :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
charleswelton
Enthusiast
Enthusiast
Jump to solution

You rock!  Let me take a look at your page and test it out.  Will let you know how it goes!

Charles

0 Kudos
charleswelton
Enthusiast
Enthusiast
Jump to solution

Just to confirm, did you update the function here?

http://www.lucd.info/2012/05/18/folder-by-path/

... or somewhere else?

Thanks...

Charles

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, perhaps you need to do a refresh.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
charleswelton
Enthusiast
Enthusiast
Jump to solution

Thanks.  I applied the updated function and it worked beautifully!

Thanks again!

Charles

0 Kudos