Hi I have the following script and I would like to amend it so that it looks at the lastlogon attribute of each user on each domain controller and then moves the user dependent on the age of the lastlogon attribute as this isn't replictaed to each DC. The script currently only queries the DC that the script is run on. So do I need IF and ELSE statements in here?
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://OU=People,dc=test,dc=co,dc=uk' WHERE objectCategory='user' " & _
"AND lastlogon <> '*'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strADsPath = objRecordSet.Fields("ADsPath").Value
Set objOU = GetObject("LDAP://OU=Logons,DC=test,DC=co,DC=uk")
intReturn = objOU.MoveHere(strADsPath, vbNullString)
objRecordSet.MoveNext
Loop
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://OU=People,dc=test,dc=co,dc=uk' WHERE objectCategory='user' " & _
"AND lastlogon <> '*'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strADsPath = objRecordSet.Fields("ADsPath").Value
Set objOU = GetObject("LDAP://OU=Logons,DC=test,DC=co,DC=uk")
intReturn = objOU.MoveHere(strADsPath, vbNullString)
objRecordSet.MoveNext
Loop