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.
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.
All Domain User accounts have been exported to a CSV file with the necessary information to allow for detection of malicious activity.
The choice of tool affects export depth and format.
Example of Not recommended command:
Get-ADUser -filter * -Properties * | Export-Csv UnSat.csv
PowerShell_ISE.exe
echo $PSVersionTable
[Environment]::Is64BitProcess
Get-ExecutionPolicy
Ensure version >= 2.0 and ByPass
or Unrestricted
execution policy.
Import-Module ActiveDirectory
$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
}
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
dsa.msc
Operator Note: This is slow and limited. Use only if PowerShell is not available.
UsersByOU.ps1
as example.Import-Module ActiveDirectory
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) |
How Security Identifiers Work
SID vs. GUID
List of PowerShell AD scripts
Date | Version | Description | Author |
---|---|---|---|
2025-05-02 | 1.9 | Enriched version with operator checklist, tooling, alt commands, best practices | Leo |