I have this mini internal app that I wrote which creates an Exchange Mailbox and an AD account. The way I have it right now is that I am creating an exchange mailbox and which is also creating an AD account by using credentials from a ASP.NET web form.
After the mailbox and the account has been created. I would like to enter the Home Phone number and their cell phone number that they have also provided onto the web form.
I have tried to push those two attributes during the creation time of the account but wasn't successful. So I am wondering how would I go abouts modifying these user objects right after creation to just enter the phone number properties.
Do you mean that your code does work but not right after creation or it does not work at all? New account might not being synchronized across multiple domain controllers (DC) immediately and it might require to call specific DC to obtain it.
Do a find user after the account is created to make sure its created, you can push phones during creation just add to the field like so, i get the values from a database that I push to the value, or you can see if account is created and then push change
values to it like other code.
.Properties("telephoneNumber").Value = phone
.Properties("ipPhone").Value = ip
.Properties("otherTelephone").Value = ip
my Check ad to see if a person exists.
Public Shared Function CheckAD(ByVal User As String) As Boolean
Dim DirEntry As DirectoryEntry = New DirectoryEntry(OUUsers, LDAPUser, LDAPPass, DirectoryServices.AuthenticationTypes.Secure)
Dim oSearcher As DirectorySearcher = New DirectorySearcher(DirEntry)
Dim result As SearchResult
Dim dir As DirectoryEntry
With oSearcher
.Filter = String.Format("(sAMAccountName={0})", User)
End With
result = oSearcher.FindOne
If Not result Is Nothing Then
CheckAD = True
Else
CheckAD = False
End If
DirEntry.Close()
End Function
Then update their account
Dim DirEntry As DirectoryEntry = New DirectoryEntry(OUUsers, LDAPUser, LDAPPass, DirectoryServices.AuthenticationTypes.Secure)
Dim oSearcher As DirectorySearcher = New DirectorySearcher(DirEntry)
Dim result As SearchResult
Dim Cn As String = String.Empty
Dim GenQual As String = String.Empty
Dim Middle As String = String.Empty
Dim phone As String = String.Empty
Dim ip As String = String.Empty
Dim zip As String = String.Empty
Dim Displayname As String = String.Empty
oSearcher.Filter = String.Format("(employeeID={0})", Edipi)
result = oSearcher.FindOne
If result Is Nothing Then
Return False
DirEntry.Close()
Else
Dim user As DirectoryEntry = result.GetDirectoryEntry
user.Properties("employeeType").Value = myDataTable(0)(0).ToString
user.Properties("mail").Value = myDataTable(0)(2).ToString
user.Properties("displayName").Value = Displayname.ToString
user.Properties("sn").Value = myDataTable(0)(3).ToString
user.Properties("givenName").Value = myDataTable(0)(4).ToString
user.Properties("initials").Value = Middle
user.Properties("generationQualifier").Value = GenQual
user.Properties("personalTitle").Value = myDataTable(0)(7).ToString
user.Properties("title").Value = myDataTable(0)(8).ToString
user.Properties("department").Value = myDataTable(0)(9).ToString
user.Properties("l").Value = myDataTable(0)(10).ToString
user.Properties("streetAddress").Value = myDataTable(0)(11).ToString
user.Properties("st").Value = myDataTable(0)(12).ToString
user.Properties("postalCode").Value = zip.ToString
user.Properties("telephoneNumber").Value = phone.ToString
user.Properties("ipPhone").Value = ip.ToString
user.Properties("otherTelephone").Value = ip.ToString
user.Properties("physicalDeliveryOfficeName").Value = myDataTable.Rows(0)(16).ToString()
user.Properties("sAMAccountName").Value = myDataTable.Rows(0)(1).ToString
user.Properties("extensionAttribute2").Value = myDataTable.Rows(0)(18).ToString
user.Properties("comment").Value = myDataTable.Rows(0)(19).ToString
user.Properties("description").Value = myDataTable.Rows(0)(20).ToString
user.CommitChanges()
user.Rename("CN=" & Cn)
Return True
user.Close()
End If
DirEntry.Close()
ComputerKazi
Member
22 Points
9 Posts
Modify a newly created user properties in AD
Jan 05, 2013 12:09 AM|LINK
Hi guys,
I have this mini internal app that I wrote which creates an Exchange Mailbox and an AD account. The way I have it right now is that I am creating an exchange mailbox and which is also creating an AD account by using credentials from a ASP.NET web form.
After the mailbox and the account has been created. I would like to enter the Home Phone number and their cell phone number that they have also provided onto the web form.
I have tried to push those two attributes during the creation time of the account but wasn't successful. So I am wondering how would I go abouts modifying these user objects right after creation to just enter the phone number properties.
Any help would be GREATLY appreciated.
Thank you.
smirnov
All-Star
24614 Points
4192 Posts
Re: Modify a newly created user properties in AD
Mar 11, 2013 07:56 PM|LINK
Do you mean that your code does work but not right after creation or it does not work at all? New account might not being synchronized across multiple domain controllers (DC) immediately and it might require to call specific DC to obtain it.
kldeutsch
Member
128 Points
360 Posts
Re: Modify a newly created user properties in AD
Mar 22, 2013 03:09 PM|LINK
Do a find user after the account is created to make sure its created, you can push phones during creation just add to the field like so, i get the values from a database that I push to the value, or you can see if account is created and then push change values to it like other code.
.Properties("telephoneNumber").Value = phone .Properties("ipPhone").Value = ip .Properties("otherTelephone").Value = ipmy Check ad to see if a person exists. Public Shared Function CheckAD(ByVal User As String) As Boolean Dim DirEntry As DirectoryEntry = New DirectoryEntry(OUUsers, LDAPUser, LDAPPass, DirectoryServices.AuthenticationTypes.Secure) Dim oSearcher As DirectorySearcher = New DirectorySearcher(DirEntry) Dim result As SearchResult Dim dir As DirectoryEntry With oSearcher .Filter = String.Format("(sAMAccountName={0})", User) End With result = oSearcher.FindOne If Not result Is Nothing Then CheckAD = True Else CheckAD = False End If DirEntry.Close() End Function Then update their account Dim DirEntry As DirectoryEntry = New DirectoryEntry(OUUsers, LDAPUser, LDAPPass, DirectoryServices.AuthenticationTypes.Secure) Dim oSearcher As DirectorySearcher = New DirectorySearcher(DirEntry) Dim result As SearchResult Dim Cn As String = String.Empty Dim GenQual As String = String.Empty Dim Middle As String = String.Empty Dim phone As String = String.Empty Dim ip As String = String.Empty Dim zip As String = String.Empty Dim Displayname As String = String.Empty oSearcher.Filter = String.Format("(employeeID={0})", Edipi) result = oSearcher.FindOne If result Is Nothing Then Return False DirEntry.Close() Else Dim user As DirectoryEntry = result.GetDirectoryEntry user.Properties("employeeType").Value = myDataTable(0)(0).ToString user.Properties("mail").Value = myDataTable(0)(2).ToString user.Properties("displayName").Value = Displayname.ToString user.Properties("sn").Value = myDataTable(0)(3).ToString user.Properties("givenName").Value = myDataTable(0)(4).ToString user.Properties("initials").Value = Middle user.Properties("generationQualifier").Value = GenQual user.Properties("personalTitle").Value = myDataTable(0)(7).ToString user.Properties("title").Value = myDataTable(0)(8).ToString user.Properties("department").Value = myDataTable(0)(9).ToString user.Properties("l").Value = myDataTable(0)(10).ToString user.Properties("streetAddress").Value = myDataTable(0)(11).ToString user.Properties("st").Value = myDataTable(0)(12).ToString user.Properties("postalCode").Value = zip.ToString user.Properties("telephoneNumber").Value = phone.ToString user.Properties("ipPhone").Value = ip.ToString user.Properties("otherTelephone").Value = ip.ToString user.Properties("physicalDeliveryOfficeName").Value = myDataTable.Rows(0)(16).ToString() user.Properties("sAMAccountName").Value = myDataTable.Rows(0)(1).ToString user.Properties("extensionAttribute2").Value = myDataTable.Rows(0)(18).ToString user.Properties("comment").Value = myDataTable.Rows(0)(19).ToString user.Properties("description").Value = myDataTable.Rows(0)(20).ToString user.CommitChanges() user.Rename("CN=" & Cn) Return True user.Close() End If DirEntry.Close()