Back to User management: Create
DESCRIPTION
Common ARS question is how to replace national characters (for ex: æ,ø,å) with general latin characters (for ex: ae, o, a) in generated user logon name (sAMAccountName) based on a user first & last names that can contain these national characters.
Here is step-by-step guid:
- Using ARS MMC Console, create a virtual attribute (VA), name it edsvaFirstName (DirectoryString syntax, single-valued, non-stored in ARS DB), and apply it to the user objec class.
- Create a second VA, name it edsvaLastName (DirectoryString syntax, single-valued, non-stored in ARS DB), and apply it to the user objec class.
- Reconnect the ARS MMC Console to refresh the console schema cache.
- Create a script module, copy-paste the SCRIPT ONE code from this article into the script module.
- Create a second script module, copy-paste the SCRIPT TWO code from this article into the second script module.
- Create a policy object with the User Logon Name Generation Policy with one or many generation rules based on the edsvaFirstName & edsvaLastName virtual attributes, not on the givenName & sn attributes (Active Directory defined attributes for user first & last names).
- Add to this policy object two script execution policies: one for SCRIPT ONE, another for SCRIPT TWO. Arrange the policies in the folowing order:
- SCRIPT ONE Script Execution Policy
- User Logon Name Generation Policy
- SCRIPT TWO Script Execution Policy
- Apply this policy object to the desired scope.
And now, it is a time to test our solution:
- Start the New User Wizard in an OU where the policy object is applied.
- In the wizard fill user first & last names containing national characters
- Press a small button with lightning (Generate button) near by User Logon Name (pre-Windows 2000) entry.
- Ensure that the generated user logon name doesn't contains national characters. All the national character should be replaced with the latin equivalents.
Cool! It works!
N.B. The SCRIPT ONE & SCRIPT TWO code uses several function from the ARS Script Policy Best Practices library. Just copy-paste these functions from the library to SCRIPT ONE & SCRIPT TWO code
SCRIPT ONE code
' *****************************************************************************
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE
'
' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
' PLEASE CONTACT QUEST PROFESSIONAL SERVICES OR CUSTOM DEVELOPMENT.
'
Option Explicit
'===========================================================================
Function Correct(ByVal strValue)
strValue= Replace(strValue, "æ", "ae")
strValue= Replace(strValue, "ø", "o")
strValue= Replace(strValue, "å", "a")
Correct = strValue
End Function
'===========================================================================
' EVENT HANDLERS
'===========================================================================
Sub onCheckPropertyValues(Request)
If (Not IsObjectClassRequested("user", Request)) Then Exit Sub
Request.Put "edsvaFirstName", Correct(GetAttribute("givenName", Request))
Request.Put "edsvaLastName", Correct(GetAttribute("sn", Request))
End Sub
Sub onPreCreate(Request)
If (Not IsObjectClassRequested("user", Request)) Then Exit Sub
Request.Put "edsvaFirstName", Correct(GetAttribute("givenName", Request))
Request.Put "edsvaLastName", Correct(GetAttribute("sn", Request))
End Sub
' ****** END OF CODE **********************************************************
SCRIPT TWO code
' *****************************************************************************
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE
'
' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
' PLEASE CONTACT QUEST PROFESSIONAL SERVICES OR CUSTOM DEVELOPMENT.
'
Option Explicit
'===========================================================================
Function Correct(ByVal strValue)
strValue= Replace(strValue, "æ", "ae")
strValue= Replace(strValue, "ø", "o")
strValue= Replace(strValue, "å", "a")
Correct = strValue
End Function
'===========================================================================
' EVENT HANDLERS
'===========================================================================
Sub onGetEffectivePolicy(Request)
If (Not IsObjectClassRequested("user", Request)) Then Exit Sub
If (Not IsAttributeGenerationRequested("sAMAccountName", Request)) Then Exit Sub
Request.Put "edsvaFirstName", Correct(GetAttribute("givenName", Request))
Request.Put "edsvaLastName", Correct(GetAttribute("sn", Request))
End Sub
' ****** END OF CODE **********************************************************