Skip to content

Instantly share code, notes, and snippets.

@ScriptingPro
Created November 22, 2017 18:06
Show Gist options
  • Save ScriptingPro/1dfc1cb33bbd3b95f9f7f44ac5629e29 to your computer and use it in GitHub Desktop.
Save ScriptingPro/1dfc1cb33bbd3b95f9f7f44ac5629e29 to your computer and use it in GitHub Desktop.
LdapConnection AddRequest SendRequest
$AuthenticationType = [System.DirectoryServices.AuthenticationTypes]::Secure
$DirectoryConnection = New-Object -TypeName System.DirectoryServices.Protocols.LdapConnection -ArgumentList "ldapserver.domain.com:777,uid=newuser,ou=people,dc=company,dc=com", $password , $AuthenticationType
$DirectoryConnection.Bind()
$DirectoryRequest = New-Object -TypeName System.DirectoryServices.Protocols.AddRequest
$DirectoryRequest.DistinguishedName = "uid= xxxx, ou=user, o=company"
$DirectoryRequest.Attributes.Add((New-Object -TypeName System.DirectoryServices.Protocols.DirectoryAttribute -ArgumentList "objectclass",@("top","organizationalPerson","person","inetorgperson","inetuser","mailrecipient","pwmuser","posixAccount"))) | Out-Null
$DirectoryRequest.Attributes.Add((New-Object -TypeName System.DirectoryServices.Protocols.DirectoryAttribute -ArgumentList "cn",($FirstName+" "+$LastName))) | Out-Null
$DirectoryConnection.SendRequest($DirectoryRequest)
@GeethaSelvam
Copy link

Hi @ScriptingPro ,
How can I add a attribute "Description" that has Key value pairs?
For ex:
$DirectoryRequest.Attributes.Add((New-Object -TypeName System.DirectoryServices.Protocols.DirectoryAttribute -ArgumentList "Description",@("AppName"="sampleapp","AppId"="1234")

It would be great if I get your help on this..Thanks in advance!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment