Jump to content
Nas

How can I change AD user last name with water UDF ? [Solved]

Recommended Posts

I was stuck on changing some areas on my username for some reason please check the script below :

#include <AD.au3>
#RequireAdmin

_AD_Open()

; this portion works just fine
_AD_ModifyAttribute("User.a", "GivenName", "John")
_AD_ModifyAttribute("User.a", "displayName", "John, Smith") 

; this portion I can't get it to work
_AD_ModifyAttribute("User.a", "Surname", "Smith")           
_AD_ModifyAttribute("User.a", "City", "Orlando")
_AD_ModifyAttribute("User.a", "State", "FL")
_AD_ModifyAttribute("User.a", "country", "US")

_AD_Close()

Basically the top portion for the Givenname and display name works perfectly but the other portion I am unable to get it to work.

Edited by Nas

Share this post


Link to post
Share on other sites

Try the following modification to get better error information:

Quote
#include <AD.au3>
#RequireAdmin

_AD_Open()

_AD_ErrorNotify(2)
; this portion works just fine
_AD_ModifyAttribute("User.a", "GivenName", "John")
_AD_ModifyAttribute("User.a", "displayName", "John, Smith") 

; this portion I can't get it to work
_AD_ModifyAttribute("User.a", "Surname", "Smith")           
_AD_ModifyAttribute("User.a", "City", "Orlando")
_AD_ModifyAttribute("User.a", "State", "FL")
_AD_ModifyAttribute("User.a", "country", "US")

_AD_Close()

 

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This simply means that the corresponding property has not been set before.

What is the value of @error and @extended after calling _AD_ModifyAttribute?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Global $aResult = _AD_GetObjectAttribute(@UserName, "Surname")
MsgBox(0,0,$aResult)

I tried this too and It didn't return anything the error is 2 and the extended is -2147352567.

Edited by Nas

Share this post


Link to post
Share on other sites
On 11/24/2019 at 1:56 PM, Nas said:
Global $aResult = _AD_GetObjectAttribute(@UserName, "Surname")
MsgBox(0,0,$aResult)

I tried this too and It didn't return anything the error is 2 and the extended is -2147352567.

@water Any feedback will be greatly appreciated :)

Share this post


Link to post
Share on other sites

Give this a try.  The AD schema at my work uses "sn" for the surname.  

Global $aResult = _AD_GetObjectAttribute(@UserName, "sn")
MsgBox(0,0,$aResult)

As an additional note.  Use ADExplorer to see what an AD object's attributes are available.  

 

Adam

Edited by AdamUL
Added ADExplorer link

Share this post


Link to post
Share on other sites

Or run the example script for _AD_GetObjectProperties. Example 1 will list all properties of the current user.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Awesome, Thank you @AdamUL thanks @water you're the best.

here is how my script looks like now, wanted to share, maybe someone will need this in the future :

#include <AD.au3>

_AD_Open()

_AD_ModifyAttribute("User.a", "GivenName", "John")
_AD_ModifyAttribute("User.a", "displayName", "John, Smith")
_AD_ModifyAttribute("User.a", "Description", "Owner")
_AD_ModifyAttribute("User.a", "physicalDeliveryOfficeName", "Downtown")
_AD_ModifyAttribute("User.a", "Title", "Admin")
_AD_ModifyAttribute("User.a", "Department", "IT")
_AD_ModifyAttribute("User.a", "proxyAddresses", "SMTP:John.Smith@server.com")
_AD_AddEmailAddress("User.a", "John.Smith@server.local")
_AD_ModifyAttribute("User.a", "mail", "John.Smith@server.com")
_AD_ModifyAttribute("User.a", "StreetAddress", "100 N Highway")
_AD_ModifyAttribute("User.a", "Title", "SysAdmin")
_AD_ModifyAttribute("User.a", "Company", "Facebook")
_AD_ModifyAttribute("User.a", "PostalCode", "60000")
_AD_ModifyAttribute("User.a", "Manager", _AD_GetObjectAttribute("John.Smith", "distinguishedName")) ; here will assign john smith as manager for user.a
_AD_ModifyAttribute("User.a", "sn", "Smith")
_AD_ModifyAttribute("User.a", "l", "Orlando")
_AD_ModifyAttribute("User.a", "st", "FL")
_AD_ModifyAttribute("User.a", "c", "US")

_AD_Close()

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Trinnon
      I have a question about the @error logging features in _AD_CreateUser.  Hopefully I am just missing something obvious.
      In my app I am creating a user if it does not exist then manipulating some attributes. 
      If the user does exist I would then call another function to remove groups from the user and modify some attributes.
      My question is...
      If the user already Exists, the _AD_CreateUser option gives $iValue = 0 and @error = 0.
      How can @error = 1 for the condition that the user already exists?
       
      I copied a small ship of the code in question along with my full .au3. 
      I am using AD UDF 1.4.9.0 (Water, thanks for the awesome work on this!!!).
      $iValue = _AD_CreateUser ($sOU, $sUser, $sCN)
      If $iValue = 1 Then
            _FileWriteLog ($Log, "Func UserCheck() - User '" & $sUser & "' successfully created ==> Calling UserAttribsNewUser Function.")
            Call ("NewUser")
      ElseIf @error = 1 Then
            _FileWriteLog ($Log, $sUser & " already exists ==> Calling UserAttribsExistingUser Function.")
            Call ("ExistingUser")
       
      AccountSettingConfigurations-Test1.au3
       
    • By water
      When working on the new function _AD_GetObjectOU (returns the OU of a user, group, computer etc.) I noticed the big performance advantage you get when using ADsPath.
      (example: processing 120 users to retrieve the OU takes 207ms compared to 1041ms - so it is about 5 times faster).
      At the moment functions either accept SamAccountName or FQDN as parameters to identify an AD object.
      Where would you benefit?
      It takes a lot fo time when you use _AD_GetObjectsInOU to retrieve objects fitting the search pattern and then need to loop through the resulting array calling _AD_GetobjectProperties for each object to retrieve additional properties.
      By using ADsPath this should run much faster.
      But it needs
      me to modify a lot of functions in the AD UDF to accept ADsPath as a parameter you to change your script What do you think? Is it worth the effort.
×
×
  • Create New...