-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_email.ps1
More file actions
27 lines (21 loc) · 741 Bytes
/
Copy pathget_email.ps1
File metadata and controls
27 lines (21 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# List of usernames
$usernames = @(
"@firstname","@firstname","@firstname"
)
# Get the desktop path
$desktopPath = [Environment]::GetFolderPath("Desktop")
$outputFile = Join-Path -Path $desktopPath -ChildPath "ADUserEmails.txt"
# Initialize an array to store results
$results = @()
foreach ($username in $usernames) {
# Fetch user information from AD
$user = Get-ADUser -Filter "SamAccountName -eq '$username'" -Property EmailAddress
if ($user) {
$results += "`$username: $($user.EmailAddress)"
} else {
$results += "`$username: Not Found"
}
}
# Write results to the text file
$results | Out-File -FilePath $outputFile -Encoding UTF8
Write-Host "Email addresses have been exported to $outputFile"