Simple Syntax Question: Store Items from Set in Array

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Anthony Stringer Anthony Stringer 1 year ago.

  • Author
  • #38134
    Profile photo of Brandon Lashmet
    Brandon Lashmet




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

    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.

  • #38136
    Profile photo of Anthony Stringer
    Anthony Stringer

    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}

You must be logged in to reply to this topic.