Forum Discussion
Change The Domain To Search With Powershell
Hi
So you are trying do dump the dc information out for each domain in the forest right?
Assuming you have the AD module installed and are on a domain joined machine then the code looks something like this:
import-module ActiveDirectory -force
$adforest=get-adforest
$domainlist=$adforest.domains
foreach($domain in $domainlist)
{
$pdc=(Get-ADDomain -identity $domain).pdcemulator
$dclist=(get-addomain -identity $domain -server $pdc ).replicadirectoryservers
foreach($dc in $dclist)
{
get-addomaincontroller -identity $dc | export-csv -notypeinformation -path dclist.csv -append
}
}
Hope this helps...
PeterJ_Inobits It does. thx.
- PeterJ_InobitsJan 17, 2020Iron Contributor
Cool. Just a quick note for reference. The following snippet will return the names of all of the attributes of a domain: get-addomain | get-member. Once you have done that and you know what attribute you are looking for, and what type it is then you can retrieve it using object notation..
Here's an example:
$addomain=get-addomain
$pdc=$addomain.pdcemulator
The same process applies to almost any object. Retrieve an instance and get-member will show the methods and properties that make up the object in question..