Forum Discussion
Change The Domain To Search With Powershell
PeterJ_Inobits, that would be great if finding the search isn't any trouble. I put together something similar. After I realized the Find Role, I had to export the DC's. Here's mine.
$AsburyDomain="asbury.localhost"
$context = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext("domain",$AsburyDomain)
[system.directoryservices.activedirectory.domain]::GetDomain($context).domainControllers | export-csv "c:\users\Desktop\Domain_Controller_List\domain.csv" -NoTypeInformation -Encoding UTF8
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...
- JimLearyJan 17, 2020Copper Contributor
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..