Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count disabled users

Status
Not open for further replies.

csc123ster

IS-IT--Management
Apr 3, 2008
2
US
Hi,

I have a script here that count the total users from each of the 3 groups in AD. How do I count the total accounts that are disabled from the 3 groups? Thanks for the advice

set objacTypes = createobject("Scripting.Dictionary")
objacTypes.Add 1, "IUsers"
objacTypes.Add 2,"ITrials"
objacTypes.Add 3, "IInternal"
for z =1 to 3
strgroup = "cn=" & objactypes.item(z) & ",ou=TONE,ou=TS,DC=dom,dc=abc,dc=net"
'wscript.echo strgroup
Set objGroup = GetObject("LDAP://" & strgroup )
i = 0
Set objDictionary = CreateObject("Scripting.Dictionary")
For Each strUser in objGroup.Member
Set objMember = GetObject("LDAP://" & strUser)
if not objmember.Accountdisabled then
'wscript.echo struser
i = i + 1
strtype = objMember.Class
If Not objDictionary.Exists(strType) Then
objDictionary.Add strType, "1"
Else
objDictionary.Item(strType) = objDictionary.Item(strType) + 1
End If
end if
Next
if z=3 then i = i +2
Wscript.Echo objactypes.item(z) & ": Total=" & i
totusrs= totusrs+i
Disabled
'For Each objType in objDictionary
' Wscript.Echo objType & ": " & objDictionary.Item(objType)
'Next

next
wscript.echo "Total: " & totusrs
 
Code:
Set objacTypes = CreateObject("Scripting.Dictionary") 
objacTypes.Add 1, "IUsers" 
objacTypes.Add 2,"ITrials" 
objacTypes.Add 3, "IInternal" 

For z = 1 To 3 
	strgroup = "CN=" & objactypes.item(z) & ",OU=TONE,OU=TS,DC=domain,DC=tld" 
	Set objGroup = GetObject("LDAP://" & strgroup ) 
	i = 0
	[red]k = 0[/red]
	Set objDictionary = CreateObject("Scripting.Dictionary") 
	For Each strUser in objGroup.Member 
		Set objMember = GetObject("LDAP://" & strUser) 
		If Not objMember.AccountDisabled then 
			'wscript.echo struser    
			i = i + 1 
			strtype = objMember.Class 
			If Not objDictionary.Exists(strType) Then 
				objDictionary.Add strType, "1" 
			Else 
				objDictionary.Item(strType) = objDictionary.Item(strType) + 1 
			End If
		[red]Else
			k = k + 1[/red]
		End If
	Next 
	[s]If z = 3 Then i = i + 2[/s]
	Wscript.Echo objactypes.item(z) & ": [red]Enabled[/red] Total="  & i
	[red]Wscript.Echo objactypes.item(z) & ": Disabled Total="  & k[/red]
	totusrs = totusrs + i 
	[s]Disabled[/s]
	'For Each objType in objDictionary 
	'    Wscript.Echo objType & ": " & objDictionary.Item(objType) 
	'Next 
Next
wscript.echo "Total: " & totusrs

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top