Compartilhar via


A simple script to manage UNIX related attributes in Windows 2003 R2

Migrating an existing environment running on Services for UNIX 3.5 to Windows 2003 R2 or above is very common these days. Generally we need to copy the values of the attributes for SFU 3.5 to the new attributes. In one of my earlier post I mentioned the difference in names of the attributes that has been introduced starting form Windows 2003 R2.

A simple way to copy the attributes can be achieved as shown below:

 

on error resume next

Const ADS_SCOPE_SUBTREE = 2

Const ADS_PROPERTY_CLEAR = 1

Const ADS_PROPERTY_UPDATE = 2

dim samname,uidnumber

samname= InputBox("Enter SAMAccountName :")

Set objConnection = CreateObject("ADODB.Connection")

Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"

objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection

objCommand.CommandText = "Select distinguishedname from 'LDAP://DC=xxx,DC=xxx' " & "where objectCategory='person' and objectclass='user' and samaccountname='" & samname & "'"

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Timeout") = 30

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

            strUserDN = objRecordSet.Fields("distinguishedname").Value

            set objuser = GetObject("LDAP://" & strUserDN & "")

            uidNumber = ""

            uidNumber = objuser.Get("msSFU30UidNumber")

            objUser.Put "uidNumber", uidNumber

            objuser.setinfo

            gidNumber = ""

            gidNumber = objuser.Get("msSFU30GidNumber")

            objUser.Put "gidNumber", gidNumber

            objuser.setinfo

            gecos = ""

            gecos = objuser.Get("msSFU30Gecos")

            objUser.Put "gecos", gecos

            objuser.setinfo

       unixHomeDirectory = ""

            unixHomeDirectory = objuser.Get("msSFU30HomeDirectory")

            objUser.Put "unixHomeDirectory", unixHomeDirectory

            objuser.setinfo

            loginShell = ""

            loginShell = objuser.Get("msSFU30LoginShell")

            objUser.Put "loginShell", loginShell

            objuser.setinfo

            msSFU30Name = ""

            msSFU30Name = objuser.Get("msSFU30Name")

            msSFU30Name = InputBox("Please Enter the value for the msSFU30Name value","",msSFU30Name)

            objUser.Put "msSFU30Name", msSFU30Name

            objuser.setinfo

            objuser.setinfo

            set objuser = nothing

objRecordSet.MoveNext

Loop

May be introducing some error checking to validate the information before copying into new attribute will make this script more effective; but I leave that to you J