• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 816
  • Last Modified:

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?
1 Solution

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
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"
    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)

Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Command for enabled users:
Get-QADUser -Enabled -SizeLimit 0

Command for disabled users:
Get-QADUser -Disabled -SizeLimit 0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now