Powershell command to see all the domain/forest info

Tiras25
Tiras25 used Ask the Experts™
on
This one always frustrate me.  Simple command to see all the domain or forest details. And it doesn't show the list all the servers or sites.  
For example: Get-ADDomain | Format-List
Gives me
ReplicaDirectoryServers            : {server1.company.com, server2.company.com, server3.company.com, server4.company.com...}   how to get all servers?

Same for this:  Get-ADForest | Format-List

Gives me:
GlobalCatalogs        : {server1.company.com, server2.company.com, server3.company.com, server4.company.com...}  how to get all servers?
Sites                 : {site1, site2, site3, site4...} how to get all sites?

I'm probably missing something very simple.  Just annoying issue!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
The result of a cmdlet are usually objects with multiple properties. These properties can contain arrays, for example, as is the case here. Format-List will stop at some point in enumerating an array, as you can see.
Answer us easy: expand the property you want to see:
Get-ADDomain | Select-Object -ExpandProperty ReplicaDirectoryServers
Get-ADForest | Select-Object -ExpandProperty GlobalCatalogs

Open in new window

Hint: above is for use in a script, when you should use no aliases and full argument names for readability.
For a quick one-liner in the console, you can shorten that (even the property, as long as there's only one result when the wildcard is evaluated):
Get-ADDomain | select -expa Repl*

Open in new window

Or access the property
(Get-ADDomain).ReplicaDirectoryServers
(Get-ADForest).GlobalCatalogs

Open in new window

Or save in a variable and access the properties:
$adDomain = Get-ADDomain
$adDomain.ReplicaDirectoryServers

Open in new window

In the console, the last method has the advantage that PS knows the variable type, and you can use tab completion when typing the property name:
$adDomain = Get-ADDomain
$adDomain.Repl<tab>

Open in new window

Jose Gabriel Ortega CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018
Commented:
Or you can show them as, comma separated values like this:
@{Name = 'Name'; Expression = {$_.Name}}

#create a custom property, and transfor the Object into string, then just expand it
Get-ADForest | Select @{n="GlobalCatalogs";e={$_.GlobalCatalogs -join ","}} | select -ExpandProperty  GlobalCatalogs

#create a custom property called ReplicaDirectoryServers, (n from name and e from expression), , and transform the Object into string, then just expand it
 Get-ADDomain | Select @{n="ReplicaDirectoryServers";Expression={$_.ReplicaDirectoryServers -join ","}} | select -ExpandProperty  ReplicaDirectoryServers

Open in new window

Author

Commented:
I knew I had to narrow it down.  Didn't know how.  
Thanks guys!
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Also, look at the Get-ADDomain and Get-ADForest part of the sample report in this article
https://www.experts-exchange.com/articles/33488/Computer-Audit-with-Powershell.html?headerLink=workspace_article

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial