Greetings everyone!
I already did a brief research on the matter, but failed to find a question, so if this question has already been answered I am sorry for the re-post.
My main problem is the following:
I am using PowerCLI version 5.1 release 2 to write scripts and manage my vCloud Director.
I have found a way to add Users into an Organization using the following script:
$role = Search-Cloud -QueryType Role -Name "Organization Administrator" | Get-CIView
$org = Get-Org -Name OrgName
$user = New-Object VMware.VimAutomation.Cloud.Views.User
$user.Name ="UserName"
$user.Password = "Password"
$user.Role = $role.href
$user.IsEnabled = $true
$org.ExtensionData.createUser($user)
The user is created using the vCloud Director, inside the required organization.
However, I have not yet found a way how to remove a user from the vCloud using the PowerCLI environment.
If anyone has any idea on how to do that, please do tell! :smileyconfused:
Thanks a lot in advance!
Welcome to the Community - I have moved your question to a more appropriate forum.
Moved to the vCloud Director PowerCLI community
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have you tried the Remove-VICredentialStoreItem commandlet? I don't know if that works for vCloud Director or not, but it looks appropriate.
Usage found at: vSphere Documentation Center
Hi, Thomas and thanks for your reply!
Unfortunately, I don't think this is what I'm looking for, mainly for three reasons:
A. I'm creating a CI (as opposed to a VI) connection, using Connect-CIServer. So, most things of the VI world are not working for me
B. I tried to remove a user using Remove-VICredentialStoreItem: I provided a Username and the IP of the CIServer as the Host. Although the cmdlet ran with no problems, the user is still there..
C. Although, when running "Get-CIUser" I get all the registered users along with the one I created (and cannot update or delete), the Get-VICredentialStoreItem cmdlet returns nothing. So, I guess I have no VICredentialStoreItems to begin with...
There must be another way.. But I have not yet found one..
I wrote some REST API calls from powershell to do this.
Here is the code I wrote, mind you I did not do any error checking. The Name has to match the "Name" in vcloud. Not to get confused with the name of the user in FullName.
**************Caution, This will remove the user from every org in vcloud.**************
$vcloud = connect-ciserver
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add('x-vcloud-authorization', $vcloud.sessionid)
$Headers.Add('accept','application/*+xml;version=31.0')
$Headers.Add('Content-Type','application/xml')
$UN = Read-Host "Please enter the User's Name from vCloud"
$users = get-ciuser -name $UN
foreach($user in $users){
$userhref = $user.href
[xml]$userxml = (Invoke-WebRequest -uri $userhref -Method get -Headers $headers).content
$takeownershiphref = $userxml.User.Link|where{$_.rel -eq "takeownership"}
$tkowner = Invoke-WebRequest -uri $takeownershiphref.href -Method post -Headers $headers
$removeuser = Invoke-WebRequest -uri $userhref -Method delete -Headers $headers}
If you want to do a specific org use this code:
$vcloud = connect-ciserver
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add('x-vcloud-authorization', $vcloud.sessionid)
$Headers.Add('accept','application/*+xml;version=31.0')
$Headers.Add('Content-Type','application/xml')
$UN = Read-Host "Please enter the User's Name from vCloud"
$orgname = Read-Host "Please enter the Org Name from vCloud"
$org = get-org -name $orgname
$user = get-ciuser -name -org $org
$userhref = $user.href
[xml]$userxml = (Invoke-WebRequest -uri $userhref -Method get -Headers $headers).content
$takeownershiphref = $userxml.User.Link|where{$_.rel -eq "takeownership"}
$tkowner = Invoke-WebRequest -uri $takeownershiphref.href -Method post -Headers $headers
$removeuser = Invoke-WebRequest -uri $userhref -Method delete -Headers $headers