Skip to content

Commit

Permalink
Create GetAllUser.ps1
Browse files Browse the repository at this point in the history
Signed-off-by: ҉αkα x⠠⠵ <[email protected]>
  • Loading branch information
4k4xs4pH1r3 authored Nov 25, 2024
1 parent 21f2c17 commit f7716d5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Microsoft/AD/GetAllUser.ps1
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

0 comments on commit f7716d5

Please sign in to comment.