This repository contains three Active Directory administration scripts:
Scan-ADComputers.ps1: PowerShell 7 inventory and validation for AD computer objects.Get-ADAdminActivity.ps1: Windows PowerShell 5.1+ Domain Controller Security log audit reporting.Manage-ADUserAccounts.ps1: Windows PowerShell 5.1+ user account reports, lockout details, focused audit lookup, and explicit reset actions.
Scan-ADComputers.ps1 is built in three capability layers:
- AD inventory and reporting
- Operational validation
- Usability and automation support
In practical terms, it can:
- Query enabled or all AD computer objects
- Scan either all matching computers or only a supplied list
- Restrict scanning to one or more OUs
- Exclude specific OUs from final results
- Flag stale devices based on inactivity age
- Export reports as CSV, JSON, and HTML
- Reuse credentials from SecretManagement or DPAPI-protected CLIXML files
- Generate targeted audit reports
- Compare the current export with a previous export and generate delta output
- Produce summary-only reports
- Validate DNS resolution
- Test TCP ports
- Attempt remote inventory collection through CIM/WinRM
- Write a run log with timestamps
- Load parameters from a JSON config file
- Write stage timing telemetry to the run log
- Optionally write CSV and JSON performance summaries
- Return structured exit codes for automation
Get-ADAdminActivity.ps1 can:
- Query writable Domain Controller Security logs
- Report AD administrative events such as user, computer, group, and policy changes
- Filter to current privileged admins with
-AdminOnly - Export sanitized CSV audit reports
- Reuse credentials from SecretManagement or DPAPI-protected CLIXML files
Manage-ADUserAccounts.ps1 can:
- Report user account summary, password age, locked-out accounts, privileged users, disabled users, and stale users
- Export single-user audit summaries and optional Security event details
- Unlock one account, enable one account, reset one password, and require password change at next logon
- Export reports as CSV, JSON, and HTML
- Reuse credentials from SecretManagement or DPAPI-protected CLIXML files
Scan-ADComputers.ps1: PowerShell 7 or laterGet-ADAdminActivity.ps1: Windows PowerShell 5.1 or laterManage-ADUserAccounts.ps1: Windows PowerShell 5.1 or later
ActiveDirectory- RSAT Active Directory tools installed on the machine
- A credential with permission to query AD
- Permission to read Domain Controller Security logs for audit reports
- If
-RemoteInventoryis used:- Remote CIM/WinRM access must be allowed
- Firewalls must permit required traffic
- The credential must have access on target machines
- If
-TestMethod Pingis used, ICMP must be allowed - If
-TestMethod WinRMor-RemoteInventoryis used, WinRM ports must be reachable - If
-ResolveDnsis used, DNS resolution must work from the machine running the script
- Active Directory modules are loaded only from the trusted Windows RSAT module path.
- CSV exports are sanitized by default to reduce spreadsheet formula injection risk.
- Existing report and log files are not overwritten unless
-ForceOverwriteis supplied. - Network output paths are rejected unless
-AllowNetworkOutputPathis supplied. - Network input paths are rejected unless
-AllowNetworkInputPathis supplied. - Stored credential files must be outside the repository directory.
- User-supplied text inputs are checked for control characters before they are used.
- Domain Controller and DNS names are validated before network calls.
Scan-ADComputers.ps1 -RemoteInventoryskips targets outside the discovered or supplied AD DNS suffix.- Generated temporary passwords in
Manage-ADUserAccounts.ps1require-ShowGeneratedPassword.
Scan-ADComputers.ps1 runs in this order:
- Read parameters and optional JSON config
- Prepare output and log paths
- Resolve explicit, stored, or prompted credentials
- Build the AD query scope and filters
- Run either a full scan or targeted scan
- Build inventory records with AD metadata
- Optionally enrich records with DNS, port, and remote inventory checks
- Export inventory, audit, summary, and delta reports as requested
- Write a run summary and exit with a structured code
Get-ADAdminActivity.ps1 runs in this order:
- Read parameters and validate output controls
- Load the trusted RSAT
ActiveDirectorymodule - Discover writable Domain Controllers unless they are supplied
- Resolve privileged group membership when
-AdminOnlyis used - Query Domain Controller Security logs for AD administrative event IDs
- Normalize event properties into CSV rows
- Apply privileged-admin filtering when requested
- Export sanitized CSV output
Manage-ADUserAccounts.ps1 runs in this order:
- Read parameters and validate identities, OU scope, paths, and safety switches
- Load the trusted RSAT
ActiveDirectorymodule - Discover domain metadata and Domain Controllers as needed
- Build user query scope from
SearchBase,SearchBaseList,ExcludeOU, andUserListPath - Run the selected mode:
Report,UserAudit,LockedOut, orReset - Query Security logs only when event details are requested
- Export CSV, JSON, and HTML reports
- For reset mode, perform explicit account actions through
ShouldProcessand write an action report
Main scan controls:
ComputerTypeModeComputerListPathSearchBaseSearchBaseListExcludeOUIncludeDisabledInactiveDays
Export and reporting controls:
ExportFormatCompareWithPreviousSummaryOnlySeparateStatusExports
Operational checks:
TestMethodSkipPingPingCountTimeoutSecondsThrottleLimitConnectivityThrottleLimitDnsThrottleLimitPortThrottleLimitRemoteInventoryThrottleLimitAdResultPageSizeAdSearchScopeTargetedQueryChunkSizePerformanceSummaryResolveDnsTestPortsRemoteInventory
Usability and connection:
ConfigPathLogPathDomainControllerDomainNameCredentialCredentialSecretNameCredentialPathOutputDirectoryNoClobberForceOverwriteAllowNetworkInputPathAllowNetworkOutputPathDisableCsvSanitization
Scan-ADComputers.ps1 writes a timestamped log file with run details and errors.
| Exit Code | Meaning |
|---|---|
0 |
Success |
1 |
General failure |
2 |
Prerequisite failure |
3 |
Config file failure |
4 |
Validation failure |
5 |
AD query failure |
6 |
Operational enrichment failure |
7 |
Export failure |
8 |
Compare/delta failure |
Fullmode queries all matching computer objects in scope.Targetedmode reads names from a file and queries AD byNameandDNSHostName.- Targeted mode also produces an audit export for requested inputs.
- Type filter (
ServervsWorkstation) - Enabled-only by default (override with
-IncludeDisabled) - Scope filters (
-SearchBase,-SearchBaseList) - Post-query OU exclusions (
-ExcludeOU) - Optional stale-device fields (
-InactiveDays)
Optional checks include:
- Connectivity (
Ping,WinRM,None) - DNS validation (
-ResolveDns) - TCP checks (
-TestPorts) - Remote inventory (
-RemoteInventory)
Supports:
- Inventory exports
- Targeted audit exports
- Separate targeted status exports
- Summary exports
- Delta exports (
-CompareWithPrevious)
Supported formats: Csv, Json, Html.
Use the script-specific manuals for complete setup, quick start, usage, examples, outputs, and safety details: