Apologize if this thread has already been raised but I'm wondering if anyone out there has a "proven" PowerCLI script that will export (migrate) the entire VM folder structure and corresponding permissions from vCenter 4.1 and import them into vCenter 5.1. Exporting and importing Roles would also be nice to have but not essential. I found a few migration scriopts but none seem to work with vCenter 5.1. Any help would be appreciated.
Thanks. Ron
Did you already check this thread Script to import/export the folder and permission structure to a new datacenter
And there are a few more in this community.
See if that works for you, otherwise let us known what doesn't work you.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc;
Appreciate the prompt reply. Had already tried Maish's script. Unfortunately the script fails in a few areas. In addition to the fact that Maish also confirms that this was not run on vCenter 5.1, the script introduces a few more variables than what is required. For example, it's designed to migrate the hosts and VMs as well.... Nonetheless, despite the fact that I removed those parts from the script, it still fails to import the folder and permissions structure.
Ron
Hi Luc;
As mentioned above, the script you suggested as well as a few others I've been able to locate within this Forum all fail in one or another. Am truly hoping you can help with this one...
I have 2 scripts which I've attached for your review. One script exports/imports vCenter Roles/Permissions while the other exports and imports folders and
corresponding permissions. Since we will be performing fresh vSphere 5.1 installs, we do not need to migrate hosts or even VMs at this time. Manual migration of VMs will take place after successful creation of VM folders/permissions.
I'm getting inconsistent and improper results mainly with Permissions when using both. This has been validated after I perform a manual check afterwards. There are also many looping errors of which I've tabled below for your info. Most of these errors were reported by other users. Unfortunately no one has yet resolved these issues.
The results of both scripts are litsed below.
1) Migrate vCenter Folders and Permissions Script
Summary: As far as importing folders are concerned, this part seems to work but getting many Folder "not found" errors; the source of whick look to be "default"
vCenter 4.1 folder hierarchy...i.e. 'Hosts & Clusters'. The following is an example of the many repetitive output errors following execution:
Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\migrate-vcenter-newest-test.ps1:84 char:44
+ $Foldername = (Get-View -id <<<< $perm.EntityId).Name
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
Exception calling "SetEntityPermissions" with "2" argument(s): "The object has already been deleted or has not been completely created"
At C:\migrate vcenter folders and permissions.ps1:170 char:35
+ $doactual.SetEntityPermissions <<<< ($entity, $setperm)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Get-Folder : 18/02/2013 5:06:49 PM Get-Folder Folder with name 'Hosts & Clusters' was not found using the specified filter(s).
At C:\migrate vcenter folders and permissions.ps1:148 char:71
+ $entity.value = ((get-datacenter $datacenter | get-folder <<<< $perm.Foldername).ID).Trimstart("Folder-")
+ CategoryInfo : ObjectNotFound: (:) [Get-Folder], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetFolder
You cannot call a method on a null-valued expression.
At C:\migrate vcenter folders and permissions.ps1:148 char:103
+ $entity.value = ((get-datacenter $datacenter | get-folder $perm.Foldername).ID).Trimstart <<<< ("Folder-")
+ CategoryInfo : InvalidOperation: (Trimstart:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
2) Export-Import vCenter Roles Script
Summary: The following is an example of the many repetitive output errors following execution:
Exception calling "SetEntityPermissions" with "2" argument(s): "
Required parameter entity is missing
while parsing call information for method SetEntityPermissions
at line 1, column 218
while parsing SOAP body
at line 1, column 207
while parsing SOAP envelope
at line 1, column 38
while parsing HTTP request for method setEntityPermissions
on object of type vim.AuthorizationManager
at line 1, column 0"
At C:\Export_Import Roles Newest.ps1:97 char:43
+ $perms = $authMgr.SetEntityPermissions <<<< ($object.MoRef,@($permission))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
A few other error messages such as.....
Exception calling "AddAuthorizationRole" with "2" argument(s): "A specified parameter was not correct.
privIds"
At C:\Export_Import Roles Newest.ps1:81 char:44
+ $roleId = $authMgr.AddAuthorizationRole <<<< ($name,$privIds)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Get-View : 18/02/2013 3:08:09 PM Get-View The request failed with HTTP status 501: Not Implemented.
At C:\Export-Import vCenter Roles .ps1:171 char:19
+ $entity = Get-View <<<< -ViewType $_.EntityType -Filter @{"Name"=$EntityName}
+ CategoryInfo : NotSpecified: (:) [Get-View], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
Set-Permission : Cannot process argument transformation on parameter 'object'. Cannot convert the "System.Object[]" value of type "System.Object[]" to type
"VMware.Vim.ManagedEntity".
At C:\Export-Import vCenter Roles .ps1:172 char:15
+ Set-Permission <<<< $entity $perm
+ CategoryInfo : InvalidData: (:) [Set-Permission], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Permission
I'm not a scripting guy so I'm not sure where the problems lies. Either the scripts cannot be run in (any) sequence or they contain cmdlets/attributes which are not
compatible with vCenter 5.1 (or maybe both).
Any assistance you can provide would be appreciated. Thx
Ron
As a matter of principle I am finalizing this thread. Although I needed to seek assistance elsewhere, I am happy to report a solution to my problem, as well as the many more who reported similar issues, has been found. I'm hopeful that by completing this thread others will benefit as well...
I've attached a new (consolidated) script which merges source data and improvements from a variety of sources to ultimately achieve migration of vCenter Roles and Privileges as well as the export/import of Datacenter/VM folders and corresponding permissions. This has been successfully tested using vCenter 4.1 and vCenter 5.1 as source and destination servers.
The script includes a number of Prerequisites and/or conditions which should be acknowledged and established in order to minimize scripting errors. There are no doubt opportunities to improve upon the functions in this script but it is believed, as a minimum, that a solid foundation has been provided.
Thanks a lot for this script, RonPSSC! That made my day!