Re: user accounts
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 17 Jan 2006 12:14:18 -0600
rodge wrote:
> We have several layers of OU's for our user accounts. I was wondering if
> there was an easy way to quickly determine the number of user accounts we
> have in active directory?
Hi,
At a command prompt, enter the command:
net user /domain
Or, run a VBScript program using ADO to count user objects:
=======================
Option Explicit
Dim objRootDSE, strDNSDomain, objConnection, objRecordset
Dim strBase, strFilter, strAttributes, strQuery, strDN
' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory.
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objRecordset = CreateObject("ADODB.Recordset")
objRecordset.ActiveConnection = objConnection
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"
' Comman delimited list of attributes to retrieve.
strAttributes = "sAMAccountName"
' ADO query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objRecordset.Source = strQuery
objRecordset.Open
Wscript.Echo "Number of users: " & objRecordset.RecordCount
' Clean up.
objRecordset.Close
objConnection.Close
Set objRootDSE = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
======================
If the VBScript is in a file called CountUsers.vbs, run it at a command
prompt with:
cscript //nologo CountUsers.vbs
Note that the VBScript program can be revised to retrieve any attribute
values desired.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
.
- Prev by Date: Re: active directory replication
- Next by Date: Re: Is it possible....
- Previous by thread: Re: user accounts
- Next by thread: Re: user accounts
- Index(es):
Relevant Pages
|