I am frequently called on for Active Directory reports for all domains in the forest. This code shows you how to use a workflow to easily do this, adding the domain data into the results:
WorkFlow Run-wfADQuery { param([string[]]$Domains,[string]$filter) ForEach -parallel ($Domain in $Domains){ InLineScript { $userList =get-aduser -filter $using:filter -server $using:Domain @(Foreach ($user in $userList){ $user | add-member -NotePropertyName "Domain" -NotePropertyValue $using:domain -Force $user }) }#End Inline $userlist = '' } #End Foreach Parallel }#End WorkFlow #Example: Multithreaded query of all users with Smith last name in all domains: $Forest = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()) $Domains = ($Forest.Domains).Name | sort -CaseSensitive $Data = Run-wfADQuery -domains $Domains -filter "SN -eq 'Smith'" $Data | select * -ExcludeProperty ps* | ogv