List All Domain Controllers In AD Forest Using PowerShell

Here is the little script i use as a function in my PowerShell profile to list domain controllers in my AD Forest .

This function lists domains, domain controllers, IPv4 addresses and their operating systems accordingly.

Sometimes It comes very handy when you need to refresh your memory, what DCs you have in your environment. This is especially true if you have more than one domain in your forest.

First part gets all domains in the forest and passes to the pipe, next part runs foreach loop (help about_foreach in PowerShell) takes domain names and pipes them to “-Server” parameter, which in turn is used by Get-Addomaincontroller to get DCs for those domains. “-Filter *” parameter is important to get all Domain Controllers.

The rest is basically grooming the stuff, select what you want to see, how you want it and etc.

To make it as a function, open your PowerShell profile and copy and paste following:

3 thoughts on “List All Domain Controllers In AD Forest Using PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *