Skip to content

Instantly share code, notes, and snippets.

@sytone
Created September 24, 2018 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sytone/a281d622727465ff83e8f4332e176c34 to your computer and use it in GitHub Desktop.
Save sytone/a281d622727465ff83e8f4332e176c34 to your computer and use it in GitHub Desktop.
Get user in AD from all domains in the forest
param (
$Filter
)
$arrayOfFQDNs = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() | select domains).Domains | select Name | % { $_.Name }
foreach ($FQDN in $arrayOfFQDNs) {
$adUser = get-aduser -Filter $Filter -properties * -server $FQDN -ErrorAction SilentlyContinue
if ($adUser -ne $null) {
break
}
}
$adUser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment