Re: user accounts

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: PASSWORD NEVER EXPIRES FIELD - URGENT HELP NEEDED - PLEASE!!!
    ... Get a dsmod.exe from Windows 2000 resource kit and use below command ... for loop. ... > Set objConnection = Nothing ... > Set objRecordSet = Nothing ...
    (microsoft.public.win2000.active_directory)
  • RE: Internet Explorer Scripts error in regular mode now too
    ... Sorry Sue If I didn't give enough Details in my troubleshooting: ... wondows uses in User Accounts to present as pictures to select. ... tried the Reg file or the register command?. ... Error message when you try to open the User Accounts item in Control Panel ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Getting the twain interface working on an XP user account
    ... That is I fiddled with the permissions, signed onto a non-admin account, and it might work once. ... I don't have those exact options on XP Home so I tried something I got on an MS forum relating to another program - tip supplied by Michael Bednarek http://mbednarek.com/ - seems to be very helpful for those programs that won't work in User accounts. ... When logged in as administrator navigate to relevant directory and from a command prompt execute following command ... you can extend it to ALL files in the folder with the command ...
    (comp.periphs.scanners)
  • RE: Internet Explorer Scripts error in regular mode now too
    ... wondows uses in User Accounts to present as pictures to select. ... "nass" wrote: ... tried the Reg file or the register command?. ... Error message when you try to open the User Accounts item in Control Panel ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Cannot Create New User
    ... Tried it and got the same message as I did with the /i command: ... mshtml.dll was loaded but the DllRegisterServer entry point was not found. ... MS-MVP Windows Shell/User ... User Accounts applet background is in White even with XP Theme enabled ...
    (microsoft.public.windowsxp.security_admin)