Locating all devices in a Forest (4 domains

Welcome Forums General PowerShell Q&A Locating all devices in a Forest (4 domains

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

1 year, 3 months ago.

  • Author
  • #83576

    Points: 0
    Rank: Member

    I am a gnats hair above a beginner in PS. I want to inventory all devices inside an AD Forest. I have 4 domains inside the forest. I was able to return the current domain with ease using this script:

    Get-ADComputer -Filter * | Out-File $OutputFile

    Is there a way to run a script that grabs all four domains, or do I need to perform 4 searches, one in each domain? Any help is appreciated


  • #83584

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    You'll have to do each domain one at a time. The easiest was would be to map a new PSDrive to each of the four domains, using the Active Directory PSProvider. Then you can change to each “drive” and run the same command. The AD commands all target, by default, whatever domain “drive” you're in at the time.

    • #83867

      Points: 0
      Rank: Member

      Thank you Don. I was able to get all of the domains to report their devices under AD control. Now I am hearing that there are some XP machines outside of the domain but I dont know where they could be, kinda like a needle in a haystack. Any thoughts on how I can accomplish this.

    • #83879

      Points: 0
      Rank: Member

      Since the XP machines are outside domain you will not have access. Either look in DHCP server or you will need network sniffer to figure out live XP desktops out there.

  • #83608

    Points: 785
    Helping Hand
    Rank: Major Contributor

    Or just use the example shown here as your starting point:


    .. and tweak as needed.

    Yet, that one is a bit long... since you qualified your PoSH experience as you have. Maybe this will work for you. Well, along with the approach Don suggested to make it easier for you to hang your hat on...

    # Get the forest information
    ($ADForestInfo = (Get-ADForest))

    ApplicationPartitions : {DC=DomainDnsZones,DC=contoso,DC=com, DC=ForestDnsZones,DC=contoso,DC=com}
    CrossForestReferences : {}
    DomainNamingMaster : DC01.contoso.com
    Domains : {contoso.com}
    ForestMode : Windows2012R2Forest
    GlobalCatalogs : {DC01.contoso.com}
    Name : contoso.com
    PartitionsContainer : CN=Partitions,CN=Configuration,DC=contoso,DC=com
    RootDomain : contoso.com
    SchemaMaster : DC01.contoso.com
    Sites : {Default-First-Site-Name}
    SPNSuffixes : {}
    UPNSuffixes : {}

    # Get data points from all computers in each domain found
    # Display formatted to the screen

    # Get data points from all computers in each domain found
    ForEach ($Domain in (Get-ADForest).Domains)
    "`n********* Working on $Domain *********"
    'Using distinguished name: ' + ($DomainSearchDN = 'DC=' + $Domain.Split('.')[0] + ',' + 'DC=' + $Domain.Split('.')[1])
    (Get-ADComputer -Filter * -Properties * -SearchBase $DomainSearchDN -Server $Domain) `
    | Select Name,SamAccountName,DNSHostName,SID,IPv4Address,

The topic ‘Locating all devices in a Forest (4 domains’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort