Thursday, November 16, 2023

Check AD user using Get-AdUser in Multi Domain Forest

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
 


4 comments:

  1. Juniper adds meaningful value because scptoolkit.io consistently features quality controller configuration tools, reliable setup instructions, and practical compatibility resources for gamers. The website reflects professionalism, usability, and dependable functionality, making controller management straightforward, efficient, and rewarding for everyone.

    ReplyDelete
  2. Truly appreciate discovering the helpful spacesniffer.info website because it provides an excellent way to analyze storage usage. The software is responsive, visuals are informative, and users can quickly clean unnecessary files with complete confidence.

    ReplyDelete

Featured Post

How to Enable and Manage the Copilot Icon in SharePoint Online: A Complete Admin Guide

Copilot in SharePoint shows up as an agent icon in the SharePoint global header. From there, users can ask questions, summarise content, a...

Popular posts