Script to assign UNIX attributes; some extra steps
Requirement to update the UID, GID and UNIX related attributes in Active Directory is very common. Using a script to assign values to these attributes needs one more check.
When we assign the UNIX attributes using UNIX attribute tab, it also increments the msSFU30MaxUidNumber attribute.
The following script replicates similar behavior in a script. BTW, I wrote this script for a Services for UNIX 3.5 and related schema.
Const ADS_SCOPE_SUBTREE = 2
Const ADS_PROPERTY_CLEAR = 1
Const ADS_PROPERTY_UPDATE = 2
dim samname,msSFU30UidNumber
samname= InputBox("Enter SAMAccountName :")
dim objSFU,msSFU30MaxUidNumber
msgbox msSFU30MaxUidNumber
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
set objSFU = GetObject(LDAP://CN=xxx,CN=ypservers,CN=YPSERV30,CN=RpcServices,CN=System,DC=xxx,DC=xxx)
objSFU.GetInfoEx Array("msSFU30MaxUidNumber", "sn"), 0
msSFU30MaxUidNumber = objSFU.Get("msSFU30MaxUidNumber")
strUserDN = objRecordSet.Fields("distinguishedname").Value
set objuser = GetObject("LDAP://" & strUserDN & "")
msSFU30UidNumber = ""
msSFU30UidNumber = objuser.Get("msSFU30UidNumber")
msgbox msSFU30MaxUidNumber
objUser.Put "msSFU30UidNumber", msSFU30MaxUidNumber
objuser.setinfo
objSFU.Put "msSFU30MaxUidNumber", msSFU30MaxUidNumber + 1
objSFU.setinfo
set objuser = nothing
set objSFU = nothing
objRecordSet.MoveNext
Loop