Check AD user using Get-AdUser in Multi Domain Forest
Clear-Host
$UserEmail = 'user1@domain.com'
$Domains = (Get-ADForest).Domains
$DClist = ForEach ($Domain in $Domains) {
Write-Host "Domain " $Domain
Get-ADDomainController -DomainName $Domain -Discover -Service PrimaryDC | Select -ExpandProperty hostname
}
$ADUsersList = ForEach ($DC in $DClist) {
Write-Host "DC: " $DC
$adUser = Get-ADUser -server $DC -Filter { UserPrincipalName -eq $UserEmail }
if (!$adUser) {
Write-Host "`t User $UserEmail not exist" -b Red
}
else {
Write-Host "`t User $UserEmail exist" -b Green
}
#Get-ADUser -server $DC -Filter * -Properties *
}
#$ADUsersList | Export-Csv -Path C:\ADUserList.csv -NoTypeInformation
$UserEmail = 'user1@domain.com'
$Domains = (Get-ADForest).Domains
$DClist = ForEach ($Domain in $Domains) {
Write-Host "Domain " $Domain
Get-ADDomainController -DomainName $Domain -Discover -Service PrimaryDC | Select -ExpandProperty hostname
}
$ADUsersList = ForEach ($DC in $DClist) {
Write-Host "DC: " $DC
$adUser = Get-ADUser -server $DC -Filter { UserPrincipalName -eq $UserEmail }
if (!$adUser) {
Write-Host "`t User $UserEmail not exist" -b Red
}
else {
Write-Host "`t User $UserEmail exist" -b Green
}
#Get-ADUser -server $DC -Filter * -Properties *
}
#$ADUsersList | Export-Csv -Path C:\ADUserList.csv -NoTypeInformation