Powershell or methods to determine the number of AD forest & Domain ?

Hi All,

I'm currently performing audit from one company to another and I'd like to know if there is any way to show how many AD forest and domains in the company ?

It can be a PowerShell script or GUI console step-by-steps.

Thanks in advance.
LVL 13
Senior IT System EngineerSenior Systems EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Schnell SolutionsSystems Infrastructure EngineerCommented:
It will be difficult to get the list of 'forests' because there is not one specific and reliable point of reference to get that information from. Many options could arise that can let you know about the existence of other forests but they will not mean that all of them are going to be necessary listed. It will be too crazy (Network traffic, review trust relationships from the domain, etc... and anyway that will not include all the information).

One very simple way to get the amount of domains within a single forest is using the command:

(Get-ADForest).Domains
This command will give you the list of domains

And with a slight change you can get the amount in numbers
((Get-ADForest).Domains).Count

These commands are assuming that you are using PowerShell with the active directory module installed. i.e. From a DC or a domain member computer with the consoles installed.
Senior IT System EngineerSenior Systems EngineerAuthor Commented:
Hi Schnell,

When I viewed the AD user and console, in the Find dialog, I can see there are three domains in the drop down under the All Directories ?

but the AD Powershell above only returns just one.
Schnell SolutionsSystems Infrastructure EngineerCommented:
Can you confirm if these domains belong to the same forest? I wonder if they are domains that belong to a different forest and they are listed there as part of a domain trust.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Schnell SolutionsSystems Infrastructure EngineerCommented:
If that is the case, try to get that topology using the "Get-AD-Trust-Topology" script:

https://gallery.technet.microsoft.com/scriptcenter/Get-AD-Trust-Topology-f8f2d1d7
Senior IT System EngineerSenior Systems EngineerAuthor Commented:
Hi Schnell.

Can you confirm if these domains belong to the same forest? I wonder if they are domains that belong to a different forest and they are listed there as part of a domain trust.

Not sure with that since I'm in a new company here.

how to look into that ?
Schnell SolutionsSystems Infrastructure EngineerCommented:
You can open the console 'Active Directory Domains and Trust' and there you will get all the domains in your forest.

From the same  console, if you right click yor domain, and go to the 'Trusts' tab, you will get the list of domains with the ones you have a trust relationship. (Even if they are domains in different forests).
Senior IT System EngineerSenior Systems EngineerAuthor Commented:
Ok, so here's the result:

Trust topology information obtained from the computer AdminLaptop007 in the domain MyDomain.com on 04/19/2017 12:09:26. 
This text file contains information on all trusts: Forest, External, Shortcut and ParentChild.
There are 2 forest trusts.
There are 0 internal (intra forest) trusts.
There are 0 external trusts.
**********************************************************************************************
Active Directory Trusts for Trusts of Type internal
*********************************
Active Directory Trusts for Trusts of Type forest
*********************************


Trust Name                                        : Trust Details for MyDomain.com|UnityNetwork.int
Local Domain (Source)                             : MyDomain.com
Trusted Domain (Target)                           : UnityNetwork.int
Trust Direction                                   : Bidirectional
Trust Type                                        : Forest
Trusted Domain Info: UnityNetwork                 : DNSName UnityNetwork.int | Domain SID: S-1-5-21-1907921415-2437651183-2526027976
Trust TopLevelNames (Name Suffix Routing)         : {UnityNetwork.int}
Trust Excluded TopLevelNames(Name Suffix Routing) : None Defined
Quarantine (SIDFiltering)                         : True
Selective Authentication                          : False





Trust Name                                        : Trust Details for MyDomain.com|MyPaymentSolution.com
Local Domain (Source)                             : MyDomain.com
Trusted Domain (Target)                           : MyPaymentSolution.com
Trust Direction                                   : Bidirectional
Trust Type                                        : Forest
Trusted Domain Info: MyPaymentSolution            : DNSName MyPaymentSolution.com | Domain SID: S-1-5-21-2000478354-1060284298-839522115
Trust TopLevelNames (Name Suffix Routing)         : {MyPaymentSolution.com}
Trust Excluded TopLevelNames(Name Suffix Routing) : None Defined
Quarantine (SIDFiltering)                         : True
Selective Authentication                          : False



Active Directory Trusts for Trusts of Type external
*********************************

Open in new window


Does this means there are three AD domains under single AD forest:

MyPaymentSolution.com <----Bi directional trust---->MyDomain.com<----Bi directional trust---->UnityNetwork.int
Schnell SolutionsSystems Infrastructure EngineerCommented:
It means that there are three different forests interconnected with trust relationships.

Notice that the Trust Type says that is "Forest". All the time that it says 'Forest' or 'External' it means that they are domains in separate forests. Like the case that you got.

When the domains are all located within the same Forest, it can say something like 'Parent', 'Child' or 'Tree' and they will appear you in the first command that was on this chat. And the three domains (each one in a different forest) are connected through trusts like you wrote:

MyPaymentSolution.com <----Bi directional trust---->MyDomain.com<----Bi directional trust---->UnityNetwork.int

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Senior IT System EngineerSenior Systems EngineerAuthor Commented:
Ah I see,

Schnell, there are 3 different AD forest and each forest contains single AD domain.
the trust is Bi directional so the AD login or account in MyPaymentSolution.com  is also recognized in UnityNetwork.int AD domain ?
Schnell SolutionsSystems Infrastructure EngineerCommented:
you are right !
Senior IT System EngineerSenior Systems EngineerAuthor Commented:
Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.