In Part1 of this article we had all the roles and permissions exported to an XML file. It’s now time to import the roles and permissions into a Virtual Center.
The script does in fact the reverse of what the script in Part 1 did.
But there were a few “gotchas“ that had to be solved before arriving at a working solution.
Duplicate Names
The script does not take into account that you can have different objects in your vSphere environment with the same name! Which imho is not a good practice in any case.
Should someone have the need for this functionality let me know and I will try to adapt the scripts.
Principals
The script does not create the principals that are mentioned in the XML file. If these principals do not exists in the environment where you want to import the roles and permissions the script will show errors.
Speed of execution
The permissions are set with an API called SetEntityPermissions.
As can be seen in the API Reference Guide this method requires a Managed Object Reference (MoRef) to a ManagedEntity. A ManagedEntity object is the parent object of most of the managed objects in vSphere.
This way of working avoids that there would have to be a separate method for each of the derived managed objects.
Continue reading →