Multiple domain search

Welcome Forums General PowerShell Q&A Multiple domain search

This topic contains 3 replies, has 3 voices, and was last updated by

 
Keymaster
8 months, 3 weeks ago.

  • Author
    Posts
  • #94633

    Participant
    Points: 0
    Rank: Member

    How is it possible to search on multiple domains in Get-ADUser Query?
    I have 3 domains – Domain1.com, Domain2.com, Domain3.com

    ForEach-Object{
    		Get-ADUser -Identity $_.samaccountname -Properties *
    	}|
    
  • #94639

    Participant
    Points: 13
    Rank: Member

    Are the domains in the same Forrest ? If so you could probably do something like this :-

    $Domains = (Get-ADForest).domains

    ForEach ($Domain in $Domains) {

    $UserAccount= Get-ADUser -server $domain |
    select SamAccountName

    $Users += $UserAccount
    }

    $Users| Export-CSV Users.csv -notypeinformation

    • #94642

      Participant
      Points: 0
      Rank: Member

      Unfortunately they aren't in the same forest.

  • #94647

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    Map a PSDrive to each domain using the AD provider. Change to each drive in turn and run your query.

The topic ‘Multiple domain search’ is closed to new replies.