Get list of active and disabled users within Active directory

I want to get list of active and disabled users within Active directory.

It is on windows server 2008

what is quickest and easiest way to get it?
itadminhelpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cvargasjCommented:
Dear,

I understand that you need list all user enabled and disabled of Active Directory.

That´s with it's script in Visual Basic Script:


‘*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
‘*-*  Script Name: ListActiveUserAccounts.vbs
‘*-*  Description: This script lists all active and disabled accounts in a
‘*-*  in a specified active directory domain. I also save the list in a CSV file.
‘*-*  Written by: Anand Venkatachalapathy
‘*-*  Date Written: July 1st 2008
‘*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

On Error Resume Next

Dim fso
Dim hFile
Dim strContainer, sStatus
Dim objConnection, objCommand, objRecordSet

‘Create a CSV text file for saving the results
Set fso = CreateObject("Scripting.FileSystemObject")
Set hFile = fso.CreateTextFile("Domain Name – Active Accounts.csv", True)
hFile.WriteLine "A/C Status" & chr(9) & " User Name" & chr(9) & "Account Name" & _
                chr(9) & "Description"

‘ Set the query settings
Const ADS_SCOPE_SUBTREE = 2
strContainer = "DC=company,DC=com"    ‘<<<<<<REPLACE YOUR DOMAIN NAME HERE

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Page Size") = 3000
objCommand.CommandText = _
  "SELECT CN,sAMAccountName,userAccountControl,description " _
   & "FROM ‘LDAP://" & strContainer & "’ " _
   & "WHERE objectCategory=’user’ "

‘Execute the Query
Set objRecordSet = objCommand.Execute

‘List the results into a CSV file
i = 1
Do Until objRecordSet.EOF
  arrDes = objRecordSet.Fields("description").Value
  If objRecordSet.Fields("userAccountControl").Value = "514" Then
    sStatus = "Disabled"
  Else
    sStatus = "       "
  End If
  WSCript.Echo sStatus,objRecordSet.Fields("CN").Value, _
          objRecordSet.Fields("sAMAccountname").Value, arrDes(0)
  hFile.WriteLine sStatus & chr(9) & objRecordSet.Fields("CN").Value & _
          Chr(9) & objRecordSet.Fields("sAMAccountname").Value & chr(9) & arrDes(0)
  objRecordSet.MoveNext
Loop

hFile.Close
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Command for enabled users:
Get-QADUser -Enabled -SizeLimit 0

Command for disabled users:
Get-QADUser -Disabled -SizeLimit 0
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.