Home > Software engineering >  Get SharePoint user's member of group list with PowerShell
Get SharePoint user's member of group list with PowerShell

Time:11-04

I'm trying to get SpGroup list for a user's member of. And Powershell Gridview column not showing all info.

Get-SPUser -Web https://contonso.com -Limit all | Where-Object {$_.UserLogin -like "*tom"} |
select UserLogin, @{name="Groups";expression={$_.Groups}}

which returns;

UserLogin        Groups
---------        ------
i:0#.w|xyx\tom   {group1, group2, group3, group4...

is there any way to show group information like line by line?

UserLogin        Groups
---------        ------
i:0#.w|xyx\tom   group1
                 group2
                 group3
                 group4
                 group5

is there any way to achieve this with | Out-GridView ?

i've also tried format-Table -auto and Out-String -Width xxx but the column is too big, even max int not working.

CodePudding user response:

Seeing how you want the output to lookk like, you need to join the items in array $_.Groups with newline characters.

To output on console you can then pipe the result to Format-Table adding the -Wrap switch:

Select-Object UserLogin, @{name="Groups";expression={($_.Groups -join [environment]::NewLine)}} | Format-Table -AutoSize -Wrap

Or if you want to use the GridView, do

Select-Object UserLogin, @{name="Groups";expression={($_.Groups -join [environment]::NewLine)}} | Out-GridView
  • Related