Author Posts

April 21, 2016 at 1:12 pm

Running

get-adforest

gives:

ApplicationPartitions : {DC=DomainDnsZones,DC=domain,DC=com, DC=ForestDnsZones,DC=corpdom,DC=com}
CrossForestReferences : {}
DomainNamingMaster    : DOMAINController.dom.com
Domains               : {dom.com}
ForestMode            : Windows2003Forest
GlobalCatalogs        : {DOMAINController1.corpdom.com, DOMAINController2.corpdom.com, DOMAINController3.corpdom.com}
Name                  : dom.com
PartitionsContainer   : CN=Partitions,CN=Configuration,DC=dom,DC=com
RootDomain            : dom.com
SchemaMaster          : DOMAINController.corpdom.com
Sites                 : {Default-First-Site-Name, Site, Site, Site}
SPNSuffixes           : {}
UPNSuffixes           : {site.com}

I'm trying to create a simply array that contains the three elements in GlobalCatalogs.

I tried the usual $DomainControllers = @(get-adforest | select globalcatalogs), but it stores the whole set in a one element array.

I want to be able to do $DomainController[1] = DOMAINController1, etc.

Surely I'm missing something simple, but can't figure it out.

Thanks for any help.

April 21, 2016 at 1:21 pm

try this

$DomainControllers = (get-adforest).globalcatalogs

# or this
$DomainControllers = get-adforest | select -expand globalcatalogs

# or this
$DomainControllers = get-adforest | % {$_.globalcatalogs}

# or this
$DomainControllers = @(get-adforest).foreach{$_.globalcatalogs}