Creating new vCloud Organization users with PowerCLI
There is not a New-CIUser cmdlet *yet*, but I'll show you the way you can do it now!
We'll need 3 things: A username, a password, and a role.
To get the role we want to assign the user, we'll need to use Search-Cloud:
This will give us a list of roles. Pick a role name. As an example, I want to add an Org admin, so I am going to run this:
The previous line queried for the role, retrieved the role object using Get-CIView and assigned it to the $role variable.
Congrats, that was the hardest part... on to the good stuff!
We need to do two things next... Get our Org object, and create a new user object:
Now we assign the fun stuff to our user object (name, password, role)!
and finally, we push the user object to our Org:
So that's it! Probably 10 lines of code and we have a new user. The secret is really in the .extensiondata of the objects like $org.
comments powered by Disqus
Search-Cloud -QueryType Role | select Name
$role = Search-Cloud -QueryType Role -Name "Organization Administrator" | Get-CIView
$org = Get-Org
$user = New-Object VMware.VimAutomation.Cloud.Views.User
$user.Name ="JakeRobinson"
$user.Password = "myPassword"
$user.Role = $role.href
$user.IsEnabled = $true
$org.ExtensionData.createUser($user)