Bianchi928
asked on
Active accounts
How can I modify this script to show the active accounts instead of disabled ones.
Thanks
Cheers
Const ADS_UF_ACCOUNTDISABLE = 2
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set WshShell = CreateObject("WScript.Shel l")
LogFile = "D:\temp\logfile.txt"
Const intForAppending = 8
Set objOutput = objFSO.CreateTextFile(LogF ile, intForAppending, False)
Set objConnection = CreateObject("ADODB.Connec tion")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Comman d")
objCommand.ActiveConnectio n = objConnection
objCommand.CommandText = _
"<GC://dc=sptyres,dc=com,d c=au>;(obj ectCategor y=User)" & _
";userAccountControl,disti nguishedNa me;subtree "
Set objRecordSet = objCommand.Execute
intCounter = 0
Do Until objRecordset.EOF
intUAC=objRecordset.Fields ("userAcco untControl ")
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
ObjOutput.WriteLine objRecordset.Fields("disti nguishedNa me") & " is disabled"
intCounter = intCounter + 1
End If
objRecordset.MoveNext
Loop
WScript.Echo VbCrLf & "A total of " & intCounter & " accounts are disabled."
objConnection.Close
Thanks
Cheers
Const ADS_UF_ACCOUNTDISABLE = 2
Set objFSO = CreateObject("Scripting.Fi
Set WshShell = CreateObject("WScript.Shel
LogFile = "D:\temp\logfile.txt"
Const intForAppending = 8
Set objOutput = objFSO.CreateTextFile(LogF
Set objConnection = CreateObject("ADODB.Connec
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Comman
objCommand.ActiveConnectio
objCommand.CommandText = _
"<GC://dc=sptyres,dc=com,d
";userAccountControl,disti
Set objRecordSet = objCommand.Execute
intCounter = 0
Do Until objRecordset.EOF
intUAC=objRecordset.Fields
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
ObjOutput.WriteLine objRecordset.Fields("disti
intCounter = intCounter + 1
End If
objRecordset.MoveNext
Loop
WScript.Echo VbCrLf & "A total of " & intCounter & " accounts are disabled."
objConnection.Close
ASKER
I just tested that and it doesn't seem alright to me. I specifically looked for an active account and it wasn't in the log.
OK, I can't find it right now, but you can just change the logic by changing this:
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
ObjOutput.WriteLine objRecordset.Fields("disti nguishedNa me") & " is disabled"
intCounter = intCounter + 1
End If
to this
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
Else
ObjOutput.WriteLine objRecordset.Fields("disti nguishedNa me") & " is enabled"
intCounter = intCounter + 1
End If
Regards,
Rob.
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
ObjOutput.WriteLine objRecordset.Fields("disti
intCounter = intCounter + 1
End If
to this
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
Else
ObjOutput.WriteLine objRecordset.Fields("disti
intCounter = intCounter + 1
End If
Regards,
Rob.
ASKER
Still not good...For starters the disable script is not good...It shows..let say 710 ..but when I manually checked on the AD it shows more than 1000..I don't know what's wrong..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to switch the same code back to show disabled users, remove the ! from CommandText filter.
ASKER
Perfect mate.. Successfully tested both
Thanks
Cheers
Thanks
Cheers
ASKER
Perfect
Great. Thanks.
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
to this:
If NOT intUAC AND ADS_UF_ACCOUNTDISABLE Then
Regards,
Rob.