-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ҉αkα x⠠⠵ <[email protected]>
- Loading branch information
1 parent
21f2c17
commit f7716d5
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Import the Active Directory module | ||
Import-Module ActiveDirectory | ||
|
||
# Define an array of domains to query | ||
$domains = @( | ||
"example1.com", | ||
"primary" | ||
) | ||
|
||
# Create an empty array to store all results | ||
$allResults = @() | ||
|
||
# Loop through each domain | ||
foreach ($domain in $domains) { | ||
Write-Host "Processing domain: $domain" | ||
|
||
try { | ||
# Get all users | ||
$users = Get-ADUser -Filter * -Server $domain -Properties whenCreated, Enabled, country | ||
|
||
# Add results to the $allResults array | ||
$users | ForEach-Object { | ||
$allResults += [PSCustomObject]@{ | ||
Domain = $domain | ||
Account = $_.Name | ||
Created = $_.whenCreated | ||
Status = if ($_.Enabled) { "Active" } else { "Inactive" } | ||
Country = $_.country | ||
} | ||
} | ||
} | ||
catch { | ||
Write-Host " Error retrieving users: $($_.Exception.Message)" | ||
} | ||
} | ||
|
||
# Export all results to CSV | ||
$allResults | Export-Csv -Path "all_users.csv" -NoTypeInformation |