Exchangemaster GmbH company logo

Exchangemaster GmbH - A Swiss IT Consultancy
Services
References
Partners
Contact
Getting Started
FAQs
Presentations
Articles
Community
Search
Popular
Tell-a-Friend
Follow Me

Follow exchangemaster on Twitter

Who's Online
We have 75 guests online
Syndicate
FAQ 000127 - How to use PowerShell to collect information about your Active Directory infrastructure PDF Print E-mail
User Rating: / 27
PoorBest 
Written by Dejan Foro   
Sep 05, 2014 at 02:54 PM

This article applies to:
Windows Server 2008 R2

In this article I will showcase how to use PowerShell to gather information about various Active Directory objects  Forest, Domains, Sites and Domain Controllers. 

Collecting information about Active Directory objects like Users, Groups, Computers etc. is given in a separate article FAQ 000132 - How to use PowerShell to collect information about AD Objects.

In order to be able to work with Active Directory PowerShell commands you will need the Active Directory PowerShell module which comes as a part of Active Directory management tools installation.


To check if PowerShell module for Active Directory is installed on the local machine use:
     Get-Module -ListAvailable
If the ActiveDirectory module is listed you can load it by using the following command:
     Import-Module ActiveDirectory


The following examples asume that you have an Active Directory Forest with multiple subdomains and that you are executing commands with an account that is member of the Enterprise Admins group.


To get a list of all domains in the Active Directory forest:
     Get-ADForest | Select-Object -ExpandProperty Domains
           This can be also written in a shorter form as:
     (Get-ADForest).Domains


To get a count of all domains in the Active Directory forest:
     Get-ADForest | Select-Object -ExpandProperty Domains | Measure-Object | Select-Object Count 
          This can be also written in a shorter form as: 
     (Get-ADForest).Domains.Count

 
To get a list of Active Directory Forest Operation Masters:
     Get-ADForest | Select-Object DomainNamingMaster,SchemaMaster

To get the information about the Active Directory Forest Operation Mode:
     Get-ADForest | Select-Object ForestMode

To get a list of all Active Directory sites: 
     Get-ADForest | Select-Object -ExpandProperty Sites | Sort-Object
           This can be also written in a shorter form as: 
     (Get-ADForest).Sites | Sort-Object

To get a count of Active Directory sites: 
     Get-ADForest | Select-Object -ExpandProperty Sites | Measure-Object | Select-Object Count
           This can be also written in a shorter form as: 
     (Get-ADForest).Sites.Count

To get a domain mode for all domains in the forest
     $DomainList = (Get-ADForest).Domains
     foreach ($Domain in $DomainList) {Get-ADDomain -Identity $Domain | Select-Object DNSRoot,DomainMode}

To get a list of domain operation masters for all domains in the forest
     $DomainList = (Get-ADForest).Domains
     foreach ($domain in $domainlist) {Get-ADDomain -Identity $domain | Select-Object DNSRoot,PDCEmulator,RidMaster,InfrastructureMaster | Format-List}

To get a list of all domain controllers in a forest, sorted alpahbetically with their IPv4 Addresses
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | Select-Object HostName, IPv4Address | Sort-Object Hostname

To get a count of domain controllers in the forest
     ((Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ }).count

To get a domain controller list, grouped by operating system
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | Select-Object Hostname,OperatingSystem | Sort-Object OperatingSystem,Hostname | Format-Table Hostname -GroupBy OperatingSystem

To get a domain controller count per operating system
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | Select-Object Hostname,OperatingSystem | Sort-Object OperatingSystem,Hostname | Group-Object OperatingSystem | Select-Object Count,Name

To get a domain controller list with operating system and service pack information
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | Select-Object Hostname,OperatingSystem,OperatingSystemServicePack | Sort-Object OperatingSystem,OperatingSystemServicePack,Hostname

To get a domain controller count per operating system and service pack
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | Select-Object Hostname,OperatingSystem,OperatingSystemServicePack | Sort-Object OperatingSystem,OperatingSystemServicePack,Hostname | Group-Object OperatingSystem,OperatingSystemServicePack | Select-Object Count,Name

To get a list of all Domain Controllers in a forest which are Global Catalogs 
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter {isGlobalCatalog -eq $True} -Server $_ } | Select-Object Hostname | Sort-Object Hostname 
           This can be also written in a shorter form as: 
     (Get-ADForest).GlobalCatalogs | Sort-Object

To get a count of global catalogs 
     (Get-ADForest).GlobalCatalogs.Count

To get a list of all Domain Controllers in the forest that are NOT configured as Global Catalogs 
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter {isGlobalCatalog -ne $True} -Server $_ } | Select-Object Hostname | Sort-Object Hostname

To get a list of all read-only domain controllers in the forest
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter {isReadOnly -eq $True} -Server $_ } | Select-Object Hostname | Sort-Object Hostname

To get a list of all Domain Controllers in the forest grouped by domain
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | Select-Object Hostname,Domain | Sort-Object Domain,Hostname | Format-Table Hostname -GroupBy Domain

To get a list of all Domain Controllers in the forest grouped by site
     (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | Select-Object Site,Hostname | Sort-Object Site,Hostname | Format-Table Hostname -GroupBy Site
 

Last Updated ( Oct 14, 2014 at 08:56 AM )
<Previous   Next>