• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

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.FileSystemObject")
Set WshShell  = CreateObject("WScript.Shell")

LogFile = "D:\temp\logfile.txt"

Const intForAppending = 8
Set objOutput = objFSO.CreateTextFile(LogFile, intForAppending, False)

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
    "<GC://dc=sptyres,dc=com,dc=au>;(objectCategory=User)" & _
        ";userAccountControl,distinguishedName;subtree"  
Set objRecordSet = objCommand.Execute
 
intCounter = 0
Do Until objRecordset.EOF
    intUAC=objRecordset.Fields("userAccountControl")
    If intUAC AND ADS_UF_ACCOUNTDISABLE Then
        ObjOutput.WriteLine objRecordset.Fields("distinguishedName") & " is disabled"
        intCounter = intCounter + 1
    End If
    objRecordset.MoveNext
Loop
 
WScript.Echo VbCrLf & "A total of " & intCounter & " accounts are disabled."
 
objConnection.Close
0
Bianchi928
Asked:
Bianchi928
  • 5
  • 4
1 Solution
 
RobSampsonCommented:
Hi, I haven't tested it, but maybe just change this:
   If intUAC AND ADS_UF_ACCOUNTDISABLE Then

to this:
   If NOT intUAC AND ADS_UF_ACCOUNTDISABLE Then

Regards,

Rob.
0
 
Bianchi928Author Commented:
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.
0
 
RobSampsonCommented:
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("distinguishedName") & " is disabled"
        intCounter = intCounter + 1
    End If

to this
    If intUAC AND ADS_UF_ACCOUNTDISABLE Then
    Else
        ObjOutput.WriteLine objRecordset.Fields("distinguishedName") & " is enabled"
        intCounter = intCounter + 1
    End If


Regards,

Rob.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Bianchi928Author Commented:
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..
0
 
RobSampsonCommented:
OK, does this help?  It works for me.

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell  = CreateObject("WScript.Shell") 

LogFile = "enabledaccounts.txt"

Const intForAppending = 8
Set objOutput = objFSO.CreateTextFile(LogFile, intForAppending, False)

Set objConnection = CreateObject("ADODB.Connection") 
objConnection.Open "Provider=ADsDSOObject;" 
Set objCommand = CreateObject("ADODB.Command") 
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.CommandText = _ 
    "<GC://dc=sptyres,dc=com,dc=au>;(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2));distinguishedName;subtree"

Set objRecordSet = objCommand.Execute 
  
intCounter = 0 
Do Until objRecordset.EOF 
	ObjOutput.WriteLine objRecordset.Fields("distinguishedName") & " is enabled" 
	intCounter = intCounter + 1 
	objRecordset.MoveNext 
Loop 
  
WScript.Echo VbCrLf & "A total of " & intCounter & " accounts are enabled." 
  
objConnection.Close

Open in new window

0
 
RobSampsonCommented:
If you want to switch the same code back to show disabled users, remove the ! from CommandText filter.
0
 
Bianchi928Author Commented:
Perfect mate.. Successfully tested both
Thanks
Cheers
0
 
Bianchi928Author Commented:
Perfect
0
 
RobSampsonCommented:
Great. Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now