Infrastructure as Code


Creating new vCloud Organization users with PowerCLI

03 Dec 2012

  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:


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