Autosize not expand all data

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

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

You have this issue because the default collection result size of a property in a format command is 4. So when you have more than 4 items in your property’s collection, you see the 4 items followed by . To get around this, you can adjust that default value using the automatic variable $formatenumerationlimit.

$formatenumerationlimit = -1 # Unlimited
$result | ft -AutoSize -Wrap # You may need to use -Wrap because your Shell program will have a limited buffer
$formatenumerationlimit = 4 # Set back to default