IncidentResponsev2

Export Users from Active Directory

Task Export List of Users from Active Directory

Conditions

Given domain credentials with the appropriate permissions and an incident response workstation with necessary tools.

Operator Note: Exporting user accounts from Active Directory is critical for identifying unauthorized accounts, password policy violations, and lateral movement indicators.

Standards

Expiration date badPwdCount Distinguished name
Enabled Given Name LastBadPasswordAttempt
Last Logon Date/Time LockedOut Group membership
Name GUID PasswordExpired
PasswordLastSet PasswordNeverExpires PasswordNotRequired
sAMAccountName SID Surname
User Principal Name When Created  

Operator Note: Exported user account data helps responders identify suspicious accounts, accounts without expiration dates, accounts never logged in, etc.

End State

All Domain User accounts have been exported to a CSV file with the necessary information to allow for detection of malicious activity.


Notes

The choice of tool affects export depth and format.

Example of Not recommended command:

Get-ADUser -filter * -Properties * | Export-Csv UnSat.csv

Manual Steps

PowerShell Method (Preferred)

Open PowerShell ISE or PowerShell:

PowerShell_ISE.exe

Validate PowerShell environment:

echo $PSVersionTable
[Environment]::Is64BitProcess
Get-ExecutionPolicy

Ensure version >= 2.0 and ByPass or Unrestricted execution policy.

Import AD Module:

Import-Module ActiveDirectory

Export users by OU (Scripted Option):

$output = Read-Host "'Y' for output to file or any key for output in GUI table view"
$fqdn = Read-Host "Enter FQDN domain"
$cred = Get-Credential

Write-Host "Contacting $fqdn domain..." -ForegroundColor Yellow
$domain = (Get-ADDomain $fqdn -Credential $cred)

$OUlist = @(Get-ADOrganizationalUnit -Filter * -Credential $cred -SearchBase $domain.DistinguishedName)

$newlist = @{}
foreach ($_objectitem in $OUlist) {
    $getUser = Get-ADUser -Filter * -Credential $cred -SearchBase $_objectItem.DistinguishedName
    $newlist.add($_objectItem.DistinguishedName, $getUser.Count)
}

if ($output -eq "Y") {
    $newlist | ft -AutoSize | Out-File .\UsersByOU.txt
} else {
    $newlist | Out-GridView
}

Export all user data from specific OU:

Get-ADUser -SearchBase "OU=Users,DC=Army,DC=Mil" -Filter * -Properties * |
Select-Object ObjectGUID, whenCreated, AccountExpirationDate, lastLogonTimestamp, @{name="MemberOf";expression={$_.memberof -join ";"}}, PasswordExpired, PasswordLastSet, PasswordNeverExpires, PasswordNotRequired, LastBadPasswordAttempt, badPwdCount, LockedOut |
Export-Csv ADUsersExport.csv -NoTypeInformation

RSAT / ADUC Method (Alternative)

Open ADUC:

dsa.msc

Perform search and export:

Operator Note: This is slow and limited. Use only if PowerShell is not available.


Running Script


Dependencies

Import-Module ActiveDirectory

Other Available Tools

Tool Platform Use Case
PowerShell + AD Module Windows Best and most scriptable export method
ADUC (RSAT - dsa.msc) Windows Manual enumeration and export
ADExplorer (Sysinternals) Windows AD object viewing, supports export (optional)
LDAP Search Tools (Linux, Mac) Cross-platform Lightweight, simple exports (optional use)

Operator Recommendations and Additional Tools

Operator Checklist

Best Practices


References

How Security Identifiers Work
SID vs. GUID
List of PowerShell AD scripts


Revision History

Date Version Description Author
2025-05-02 1.9 Enriched version with operator checklist, tooling, alt commands, best practices Leo