0

I am trying to locate the XP computer accounts broken down by Business. We have several different business' housed across several domains.

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...

Business1.txt contains...

Business1.ad.com/Desktop/BusinessUnitA
Business1.ad.com/Desktop/BusinessUnitB
Project1.ad.com/Desktop
Project2.ad.com

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 connect-QADService -Service 'Business1.ad.com'. It seemed like this would add a considerable amount of overhead though as some domains have 150,000 computer accounts to check.

Any suggestion of strategy for dynamically switching the domain based on my txt file lists?

Here is my script as it stands...

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 
Decorius
  • 23
  • 1
  • 2
  • 5

1 Answers1

0

If you first read all text files (maybe add the filename as an object attribute so you know where it came from), it shouldn't be too hard to sort uniqely on each domain and then have the script do its search domain by domain. That way you would only have to do a connect once for each domain.

From the top of my head (completely un-tested code) I would do something like:

    $files = get-childitem "C:\SomeFolder"
    #Construct an array to hold objects
    $OUSearchList = @()
    foreach ($file in $files)
    {
        $content = get-content $file
        #Get-content returns an array of lines - iterate
        foreach ($line in $content)
        {
            #Construct custom object
            $myobj = "" | Select OUPath, Filename, Domain
            $myobj.OUPath = $line
            $myobj.FileName = $File.Name
            $myobj.Domain = $myobj.OUpath.Split("/")[0]
            $ouSearchList += $myobj
        }

    }

    #Get the unique domains
    $Domains = $OUSearchList | select Domain -Unique

    #List through all the search paths, domain by domain
    foreach ($domain in $domains)
    {
        $DomainOUSearchPaths = $OUSearchList | where {$_.Domain -eq $domain}
        foreach ($search in $DomainOUSearchPaths)
        {
            $searchpath = $search.OUPath
            $searchFileName = $search.filename
            #put search logic in here

        }

    }
Trondh
  • 3,221
  • 1
  • 25
  • 34