title: Powershell searching multiple domains
body: <p>I am trying to locate the XP computer accounts broken down by Business.  We have several different business' housed across several domains.</p>
  
  <p>I have a collection of different txt files (BusinessX.txt), one for each business that lists the locations where the business' computer accounts are stored.  Each list can have several different OUs in several domains and/or root level domains. For example...</p>
  
  <p>Business1.txt contains...</p>
  
  <pre><code>Business1.ad.com/Desktop/BusinessUnitA
  Business1.ad.com/Desktop/BusinessUnitB
  Project1.ad.com/Desktop
  Project2.ad.com
  </code></pre>
  
  <p>I have my search working to locate the XP computer accounts for a single domain.  I am unsuccessful when I try to expand the search to dynamically change between domains based on my lists. I was considering putting an "if" statement inside my ForEach-Object loop to validate the domain and switch it with <code>connect-QADService -Service 'Business1.ad.com'</code>.  It seemed like this would add a considerable amount of overhead though as some domains have 150,000 computer accounts to check.</p>
  
  <p>Any suggestion of strategy for dynamically switching the domain based on my txt file lists?</p>
  
  <p>Here is my script as it stands...</p>
  
  <pre><code>get-content $Business1.txt |
  ForEach-Object {get-qadcomputer -SearchRoot $_ -OSName '*XP**' -DontUseDefaultIncludedProperties -IncludedProperties OSName, CanonicalName, PwdLastSet, LastLogon, LastLogonTimeStamp} |
  Select OSName, canonicalName, PwdLastSet, LastLogon, LastLogonTimeStamp |
  Export-Csv “C:\XP_Computers_Business1_$((Get-Date).ToString('yyyy-MMM-dd_hh-mm-ss')).csv“ -NoTypeInformation 
  </code></pre>