scotthowe.com - oracle, mssql, and general systems administration blog...

  • my portfolio
  • my code-projects
  • xml sitemap
  • contact
Home

Navigation

  • Recent posts

Primary links

  • My Portfolio
  • My Code-Projects
  • XML Sitemap
  • Contact

Flickr recent photos

DSC00165DSC00164DSC00163DSC00162

User login

  • Create new account
  • Request new password

RDN Modify Script

' #####################################################################
' # RDN Modify
' # Program that uses that replaces the RDN with the users display name.
' # It can also fill in first and last names.
' #
' # Make sure you specify the Path so that it looks in the right place.
' ######################################################################


<job id="RDN Modify">
<script language="VBScript">

Function CorrectRDN(Parent, ADsPath, newCN)

WScript.Echo currUser & " " & newCN
Set objParent = GetObject(Parent)
objParent.MoveHere ADsPath, newCN

End Function


Parent = "LDAP://OU=Users,DC=sample,DC=com" ' ## Change this to whatever ou you want to find user accounts in
Set objUserOU = getobject(Parent)

i = 0
for each colUser in objUserOU

If InStr(colUser.displayName, ",") > 0 Then


Pos = InStr(4,colUser.distinguishedName, "=")
RDN = Mid(colUser.distinguishedName, 4,Pos-7) ' start at the fourth to skip the CN=

Wscript.Echo colUser.displayName & " " & colUser.sAMAccountName
commaPos = InStr(1,colUser.displayName, ",")
lastName = Left(colUser.displayName, commaPos-1)
firstName = Right(colUser.displayName, Len(colUser.displayName)-commaPos)

if RDN = colUser.sAMAccountName Then
newCN = "CN=" & lastName & "\," & firstName
CorrectRDN Parent, colUser.ADsPath, newCN
i=i+1
End If


' ################################################
' Update the first and first and last names

If colUser.givenName = "" Then
WScript.Echo Trim(firstName)
colUser.Put "givenName", Trim(firstName)
End If
If colUser.SN = "" Then
WScript.Echo Trim(lastName)
colUser.Put "SN", lastName
End If
colUser.SetInfo
' ################################################

End If

Next


Wscript.Echo i & " Users found with matching username and relative distinguished name."

</script>
</job>

Search

External Links

  • Richardfoote.wordpress.com
  • voug.org
  • xkcd.com

Photo Galleries

  • 08 Spring Flowers
  • Baby Matthew
  • Fall 08 Monticello Trip
  • 1 Year Old
  • Christmas 08 on New Hampshire Ave
  • Snow in March
  • Matthew in the snow
  • May 2009
  • my portfolio
  • my code-projects
  • xml sitemap
  • contact