Joao
Fri Feb 29 07:46:58 CST 2008
On 29 fev, 04:13, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> Joao wrote:
> >I need to find a way (script?) to change several users in a especial
> > OU
>
> > [displayName] looks like "John Albert Taylor (OPER)"
>
> > need to get "only" first name from [displayName] and change the
> > [givenName] to "John"
>
> > need to get "only" middle and last name from [displayName] and change
> > the [sn] to "Albert Taylor"
>
> > can consider the first " (" end of name
>
> > can help me ?
>
> Names can be very difficult to parse. You cannot assume that everyone has =
a
> middle name. I have seen users with names like M. Elizabeth Johnson. Some
> people may have Jr. or Sr. There are many forms. I might try code similar
> to:
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> ' Bind to OU.
> Set objOU =3D GetObject("LDAP://ou=3DSales,ou=3DWest,dc=3DMyDomain,dc=3Dco=
m")
>
> ' Enumerate all users in the OU.
> objOU.Filter =3D Array("user")
> For Each objUser In objOU
> =A0 =A0 ' Retrieve display name.
> =A0 =A0 strDisplayName =3D objUser.displayName
>
> =A0 =A0 ' Parse full name.
> =A0 =A0 intIndex =3D Instr(strDisplayName, " (")
> =A0 =A0 strName =3D Left(strDisplayName, intIndex - 1)
> =A0 =A0 arrNames =3D Split(strName, " ")
> =A0 =A0 ' Determine first and last names.
> =A0 =A0 strFirst =3D arrNames(0)
> =A0 =A0 strLast =3D ""
> =A0 =A0 For k =3D 1 To UBound(arrNames)
> =A0 =A0 =A0 =A0 If (k =3D 1) Then
> =A0 =A0 =A0 =A0 =A0 =A0 strLast =3D arrNames(k)
> =A0 =A0 =A0 =A0 Else
> =A0 =A0 =A0 =A0 =A0 =A0 strLast =3D strLast & " " & arrNames(k)
> =A0 =A0 =A0 =A0 End If
> =A0 =A0 Next
> =A0 =A0 ' Assign first and last names.
> =A0 =A0 objUser.givenName =3D strFirst
> =A0 =A0 objUser.sn =3D strLast
> =A0 =A0 objUser.SetInfo
> Next
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -
http://www.rlmueller.net
> --
many thanks!