Output {}

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Duane Haas Duane Haas 3 months, 1 week ago.

  • Author
    Posts
  • #52528
    Profile photo of Duane Haas
    Duane Haas
    Participant

    I have the following:

    $Groups = Get-ADGroup -Filter {Name -like "LA*"}
    foreach ($group in $groups) 
        {
        get-adgroupmember $group.name| where {$_.objectclass -eq 'Group'} | ft $group.name, name
        }
    

    I'm just trying to cleanup the output, I would prefer to see:

    $group.name Name
    $group.name Name
    $group.name Name
    $group.name Name

    vs. what I'm getting:

    LA-STGGENAPP01 name
    ————– —-
    {} DP-IT-Admin-DBA-NonProd

    LA-STGGLLAND02 name
    ————– —-
    {} DP-IT-Admin-DBA

    LA-STGRPT01 name
    ———– —-
    {} DP-IT-Admin-DBA-NonProd

    LA-STGSSAS01 name
    ———— —-
    {} DP-IT-Admin-DBA-NonProd

    Still learning powershell so be nice 🙂

  • #52535
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So, your problem is here:

    ft $group.name, name

    This is telling Format-Table to create one column **named whatever is in $group.name**. The -Properties parameter of Format-Table is a list of columns you want displayed, not the **contents of those columns**.

    You might try something like:

    Format-Table @{n='GroupName';e={ $group.name }},Name

    And see if that's more to your liking?

    • #52537
      Profile photo of Duane Haas
      Duane Haas
      Participant

      AWESOME! Thanks @DonJones for the nice explanation and that created exactly what i was looking for. Is there a way when doing the foreach to have it output everything into a single table, output currently:

      GroupName       Name                   
      ---------       ----                   
      LA-TST3GENAPP01 DP-IT-Admin-DBA-NonProd
      
      
      
      GroupName      Name                             
      ---------      ----                             
      LA-TSTCRDAPP06 DP-TradeOpsTeam-Developer-NonProd
      
      
      
      GroupName      Name                   
      ---------      ----                   
      LA-TSTGENAPP01 DP-IT-Admin-DBA-NonProd
      
      
      
      GroupName   Name                   
      ---------   ----                   
      LA-TSTRPT01 DP-IT-Admin-DBA-NonProd
      
      
      
      GroupName    Name                   
      ---------    ----                   
      LA-TSTSSAS01 DP-IT-Admin-DBA-NonProd
      

      vs. say:

      
      GroupName    Name                   
      ---------    ----                   
      LA-TSTSSAS01 DP-IT-Admin-DBA-NonProd
      LA-TSTRPT01 DP-IT-Admin-DBA-NonProd
      
      
  • #52545
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Change the Format-Table to Select-Object and try it. The problem now is that you're creating a new table "foreach group in groups," right? It'll default to table format anyway since it's only two properties.

    • #52547
      Profile photo of Duane Haas
      Duane Haas
      Participant

      Thats perfect, just as you described:

      GroupName      Name                   
      ---------      ----                   
      LA-STGGENAPP01 DP-IT-Admin-DBA-NonProd
      LA-STGGLLAND02 DP-IT-Admin-DBA        
      LA-STGRPT01    DP-IT-Admin-DBA-NonProd
      LA-STGSSAS01   DP-IT-Admin-DBA-NonProd
      LA-TST2GENA... DP-IT-Admin-DBA-NonProd
      LA-TST3GENA... DP-IT-Admin-DBA-NonProd
      LA-TSTCRDAPP06 DP-TradeOpsTeam-Deve...
      LA-TSTGENAPP01 DP-IT-Admin-DBA-NonProd
      LA-TSTRPT01    DP-IT-Admin-DBA-NonProd
      LA-TSTSSAS01   DP-IT-Admin-DBA-NonProd
      

You must be logged in to reply to this topic.