VMware Cloud Community
barnette08
Expert
Expert

Import LDAP Users

Has anyone attempted to import LDAP users via PowerCLI?  I have a list of 65 users that need to be imported and I would like to save some time on all the clicks.  I'm hoping I can get the information in a CSV file, but wasn't sure if anyone has tried this out and gotten it to work yet. Thanks in advance!

0 Kudos
7 Replies
Zsoldier
Expert
Expert

Can you elaborate a bit?  Import LDAP users into where and to do what?

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
barnette08
Expert
Expert

basically I would like to connect to the organization (which already has an LDAP source created), and import 65 users as vApp Authors.

0 Kudos
IamTHEvilONE
Immortal
Immortal


Did you ever get this sorted out?  I'd like to test out a similar script.  take in a list of usernames, and import them into an Org as LDAP based Users via PowerCLI.


I know it's possible from the REST API, as you just dictate that it's an external source for the user information:


<IsExternal>true</IsExternal>


0 Kudos
IamTHEvilONE
Immortal
Immortal

I figured it out shortly afterwards.

from here: Automating creation of vCD Organizations, Users and Org vDCs | VMware PowerCLI Blog - VMware Blogs

Setup ldap for the Org.

# Connect to the vCloud instance

connect-ciserver

# Get your Org Reference

$OrgRef = Get-Org -Name "NameOfOrganizationToImportUsers"

# you make a new user object

$NewUser = New-Object VMware.VimAutomation.Cloud.Views.User

# The role line assumes you are only connected to the vCloud that you want to do this in, which is the default CI Server you connected to.

$NewUserRole = $global:DefaultCIServers[0].ExtensionData.RoleReferences.RoleReference | Where {$_.Name -eq "vApp User"}


# These are the minimum attributes required to import the user and have the account enabled:

# replace the username with the actual login from the LDAP source, whatever that is

$NewUser.Name = "Username@In.LDAP"

$NewUser.IsEnabled = "True"

$NewUser.IsExternal = "True"

$NewUser.Role = $NewUserRole


# Actually create the user account


$OrgRef.ExtensionData.CreateUser($NewUser)

0 Kudos
zvyas27
Contributor
Contributor

Hi,

Were you able to import users from LDAP? I am stuck with the same problem.

0 Kudos
SDK_User_99
VMware Employee
VMware Employee

For SAML users you need to specify the below line.

$NewUser.providerType = "SAML"

You don't specify explicitly the provider type for importing LDAP  users.

0 Kudos
moellerjot
Enthusiast
Enthusiast

Hi, 
This may can help you to Import AD User into vCD.
Try this via Powershell (Tested with vcd10.x).

Getting Users from AD: 

 

### ModuleType Version    Name               ###
### Manifest   1.0.0.0    ActiveDirectory    ###              
$user=(GET-adGroupMember -Identity "CN=orgname-orgadmins,OU=application,DC=domain,DC=net").Name
$USER|foreach {write-host $_}

 

Add User via VimAutomation: 

 

### VMware.VimAutomation.Cloud/12.0.0.15940183 ###
... 
$OrgED = (Get-Org $Org).ExtensionData
$orgAdminUser = New-Object VMware.VimAutomation.Cloud.Views.User
        $orgAdminUser.Name = $Name
        $orgAdminUser.FullName = $FullName
        $orgAdminUser.EmailAddress = $EmailAddress
        $orgAdminUser.Password = $Pasword
        $orgAdminUser.Telephone= $MyTel
        $orgAdminUser.IsEnabled = $True
        $orgAdminUser.IsExternal = $True
        $orgAdminUser.IM = date
        $orgAdminUser.StoredVmQuota = '0'
        $orgAdminUser.DeployedVmQuota = '0'

        $vcloud = $DefaultCIServers[0].ExtensionData

        ## Find Role
        if ( ([string]::IsNullOrWhiteSpace($Rolle)) ) {
            $orgAdminRole = $OrgED.RoleReferences.RoleReference | Where-Object {$_.Name -eq "Organization Administrator"}
        }
          if ( ($Rolle) ) {
            $orgAdminRole = $OrgED.RoleReferences.RoleReference | Where-Object {$_.Name -eq $Rolle}
        }
$orgAdminUser.Role = $orgAdminRole

## Create User
$orgAdminUser
...

 

#DontTryInProduction 
#NoGuarantee
#NoSupport
#NoBackupNoPity

Not being able to do something is no reason not to do it. 🙂 
0 Kudos