Using Windows PowerShell to list domain controllers in each of the domains within an ADS forest
Submitted by guvnor on Thu, 04/22/2010 - 15:05
Using Windows PowerShell to list domain controllers in each of the domains with an ADS forest
If ever you need to get the list all of the domain controllers within a forest you can use powershell to do it for you and write it to a file. Note, of course your computer must Windows Powershell installed for this to work! Here is how: Create a new file with the following code on your computers file system. I am calling mine getDC.ps1 and i am saving it under c:\scripts#Create a variable object called $myForest and assign the forest that the computer is running part of. $myForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() #Connect to the Sites propery of the $myForest and for each of the sites list the domain controllers and the just show me the name of the site and domain controller. Save the content to a file called mydcs.txt $myforest.Sites | % { $_.Servers } | Select Name, Domain | out-file mydcs.txt