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 7 months, 2 weeks ago.

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

    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.

  • #38136
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    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.