Output {}

Welcome Forums General PowerShell Q&A Output {}

Viewing 2 reply threads
  • Author
    Posts
    • #52528
      Inactive
      Topics: 1
      Replies: 2
      Points: 0
      Rank: Member

      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
      Keymaster
      Topics: 13
      Replies: 4872
      Points: 1,870
      Helping HandTeam Member
      Rank: Community Hero

      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
        Inactive
        Topics: 1
        Replies: 2
        Points: 0
        Rank: Member

        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
      Keymaster
      Topics: 13
      Replies: 4872
      Points: 1,870
      Helping HandTeam Member
      Rank: Community Hero

      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
        Inactive
        Topics: 1
        Replies: 2
        Points: 0
        Rank: Member

        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
        
Viewing 2 reply threads
  • The topic ‘Output {}’ is closed to new replies.