Hello,
I'm trying to enumerate a set of users in a particular OU and then modify a property in every account. The problem I'm having is I can only pull the Canonical name and I need the sAMAccountName in order to bind to their account. I realize the user.cn returns the Canonical name, is there a property that returns the sAMAccountName instead? Any help would be appreciated...thanks
I'm trying to enumerate a set of users in a particular OU and then modify a property in every account. The problem I'm having is I can only pull the Canonical name and I need the sAMAccountName in order to bind to their account. I realize the user.cn returns the Canonical name, is there a property that returns the sAMAccountName instead? Any help would be appreciated...thanks
Code:
Option Explicit
Dim defaultnamingcontext, DeskAuth, objOU, user, userLDAP
DeskAuth = "SLogic"
defaultnamingcontext = (GetObject("LDAP://rootDSE")).Get("defaultNamingContext")
Set objOU = GetObject("LDAP://OU=Users-IS Dept, OU=Users-All," & defaultNamingContext)
objOU.Filter = Array("user")
For Each User In objOU
[b]userLDAP = SearchDistinguishedName(User.cn)[/b]
Set objUser = GetObject("LDAP://" & userLDAP)
objUser.Put "scriptPath", DeskAuth
objUser.SetInfo
Next
wscript.echo "Script Finished"
Function SearchDistinguishedName( vSAN )
On Error Resume Next
Dim oRootDSE, oConnection, oCommand, oRecordSet
defaultNamingContext = GetObject("LDAP://rootDSE").Get("defaultNamingContext")
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
'On Error GoTo 0
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & defaultnamingcontext & ">;" _
& "(&(objectCategory=User)" _
& "(samAccountName=" & vSAN & "));" _
& "distinguishedName;subtree"
Set oRecordSet = oCommand.Execute
' you must use a for/next here or you will get errors
' a recordset is always a collection
While Not oRecordSet.EOF
SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")
oRecordset.MoveNext
Wend
oConnection.Close
End Function