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:
Search-Cloud -QueryType Role | select Name
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:
$role = Search-Cloud -QueryType Role -Name “Organization Administrator” | Get-CIView
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:
$org = Get-Org
$user = New-Object VMware.VimAutomation.Cloud.Views.User
Now we assign the fun stuff to our user object (name, password, role)!
$user.Name =“JakeRobinson”
$user.Password = “myPassword”
$user.Role = $role.href
$user.IsEnabled = $true
and finally, we push the user object to our Org:
$org.ExtensionData.createUser($user)
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.
March 4th, 2013 at 1:25 am
Could you please maybe explain how did you find how to push the user object into the Org? Where is this method documented? A search for “createUser” in the Doc Center is not much help. An explanation on how to find the method and its syntax would be great. Thanks!
March 6th, 2013 at 10:33 am
Hi Tim,
In the vCloud API Schema reference, you can find the user element by clicking on all elements, and then clicking on user. In there, you will find the PUT method for the user object:
https://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/types/UserType.html
Good luck!
Cheers,
Jake
March 16th, 2013 at 12:30 am
I am still confused by this. I did go to the link above, I do see a “PUT /admin/user/{id}” at the bottom of the page. However i fail to see the link between this and how this was invoked in:
$org.ExtensionData.createUser($user)
To put it from a different perspective I am wondering how how would you research and get the methods and their syntax available in the ExtensionData of an object. Thanks for replying and any feedback would be greatly appreciated! Tim.