Autosize not expand all data

Welcome Forums General PowerShell Q&A Autosize not expand all data

Viewing 1 reply thread
  • Author
    Posts
    • #246108
      Participant
      Topics: 2
      Replies: 1
      Points: 17
      Rank: Member

      Hi All,

      How can i expand the value of group to all groups and make is readable? tried autosize, didn’t work

       

      $result = @(
      
      $Userslist = Get-ADUser -Identity Meirp
      foreach ($user in $Userslist) {
      $Groups = Get-ADPrincipalGroupMembership -Identity $user | select -ExpandProperty Name
      
      [psobject]@{
      
      "UserName" = $user | select -ExpandProperty Name
      "groupName" = $Groups
      
      
      }
      
      }
      )
      
      $result | ft -AutoSize
      
      Name      Value                                                             
      ----      -----                                                             
      groupName {Domain Users, Server Management, Domain Admins, Schema Admins...}
      UserName  xxxxx xxxxx
      • This topic was modified 5 days, 12 hours ago by Meropr36.
    • #246147
      Participant
      Topics: 5
      Replies: 2413
      Points: 6,202
      Helping Hand
      Rank: Community MVP

      You have several options to get these information. I think it depends on what you need it for. Sometimes it’s enough to “expand” the array members and “join” them as strings:

      $Userslist = Get-ADUser -Identity Meirp -Properties MemberOf
      $result = 
      foreach ($user in $Userslist) {
          [PSCustomObject]@{
              UserName = $user.Name
              MemberOf = $user.MemberOf -join ','
          }
      }
      $result | Format-Table -AutoSize

      If you don’t want the groups with their distinguished names you have to do one step more. You could do it like this:

      $Userslist = Get-ADUser -Identity Meirp -Properties MemberOf
      $result = 
      foreach ($user in $Userslist) {
          $Groups = foreach($Group in $User.MemberOf){
              Get-ADGroup -Identity $Group
          }
          [PSCustomObject]@{
              UserName = $user.Name
              MemberOf = $Groups.Name -join ','
          }
      }
      $result | Format-Table -AutoSize

      … or like this:

      $Userslist = Get-ADUser -Identity Meirp -Properties MemberOf
      $result = 
      foreach ($user in $Userslist) {
          $Groups = Get-ADPrincipalGroupMembership -Identity $user.SamAccountName
          [PSCustomObject]@{
              UserName = $user.Name
              MemberOf = $Groups.Name -join ','
          }
      }
      $result | Format-Table -AutoSize
Viewing 1 reply thread
  • You must be logged in to reply to this topic.