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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need a script for total users and computers

Status
Not open for further replies.
Jul 27, 2004
397
0
0
US
I need a script that will just give me a total of active users and computers in our domain. I have looked at the Microsoft Technet Script Repository but I can't find a script to do either of these. Can someone please post a script that does these things. This can't be an auncommon request is it.
Thanks

Systems Administrator
A+, Network+, MCSA 2000, MCSE 2000
MCSA (2003), MCSE 2003, CCNA
 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
My FAQ faq329-4871 provides a script to generate a list of Domain Computers. You should be able to modify that to gather up all of your user info as well.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
I haven't tried anything other than searching for scripts. I do not know how to write scripts but I need to gather this data rather quickly. I just need a total count on computers and active users. I thought I could find some scripts already wrote, figured it was a common thing. I couldn't find anything so I had to turn here.

Systems Administrator
A+, Network+, MCSA 2000, MCSE 2000
MCSA (2003), MCSE 2003, CCNA
 
This is a script I have to count the computers and users. You will need to update the strGroupDN with the OU your computers are in and the name of your Domain. Also when you want to count your users then change the ou again and change the '(objectClass=Computer)' from computer to user.

---
strGroupDN = "ou=UPDATE,DC=UPDATE,DC=local"
Set oConfig = GetObject("LDAP://" & strGroupDN)
Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open ""

strQuery = "<" & oConfig.adspath & ">;(&(objectClass=Computer));samaccountname;subtree"
Set oRS = oConn.Execute(strQuery)

While Not oRS.EOF
c = i + 1
oRS.MoveNext
Wend
msgbox c

Set oConfig = Nothing
Set oConn = Nothing
Set oRS = Nothing
---

Hope this helps.
 
The script posted above will only enumerate computers and not users.

The following script which is based off of the above posted will report both. Please note that it also does not require modification to run. It will determine your AD iformation automatically.

Code:
'==========================================================================
'
' NAME: ComputerUserCount.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' DATE  : 8/10/2006
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.

' COMMENT: 
'
'==========================================================================

Dim oRootDSE, oConnection, oCommand, oRecordSet

Set oRootDSE = GetObject("LDAP://rootDSE")
Set oConfig = GetObject("LDAP://" & oRootDSE.get("defaultNamingContext")) 
Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open ""

strQuery1 = "<" & oConfig.adspath & ">;(&(objectClass=Computer));samaccountname;subtree"
Set oRS = oConn.Execute(strQuery1)
While Not oRS.EOF
    c = c + 1
    oRS.MoveNext
Wend

strQuery2 = "<" & oConfig.adspath & ">;(&(objectClass=User));samaccountname;subtree"
Set oRS = oConn.Execute(strQuery2)
While Not oRS.EOF
	u = u + 1
    oRS.MoveNext
Wend

MsgBox "Total # Computers:" & c & vbCrlf & "Total # Users:" & u

Set oConfig = Nothing 
Set oConn = Nothing 
Set oRS = Nothing

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
rather than doing this chunk:

While Not oRS.EOF
u = u + 1
oRS.MoveNext
Wend

you can simply just use oRS.RecordCount A little quicker, if you JUST want a count.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top