0

In one of our O365 SharePoint sites, we have a ton of different permissions groups with various people in each one. Is it possible to generate a report that lists each of these permissions groups and who is in each one?

I have searched for the answer, but I have been unable to find it. I thought it would be something that is readily available as something many would need, bit I can't find it.

Can anyone help me out with a PowerShell script or a way to do this online?

Thanks.

1 Answer 1

0

You can run the PowerShell script in SharePoint Online Management Shell to get a CSV report for SharePoint site collection groups and members. Please change the relevant information for your own environment.

Function Get-SiteGroup-Members 
{ 
    param ($sSiteUrl,$sUserName,$sPassword,$FileName) 
    try 
    {    
        #SPO Client Object Model Context 
        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) 
        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)   
        #$spoCredentials = New-Object System.Net.NetworkCredential($sUserName, $sPassword)    # for on premise
        $spoCtx.Credentials = $spoCredentials        

        $web = $spoCtx.Web
        $spGroups =$web.SiteGroups

        $spoCtx.Load($web)
        $spoCtx.Load($spGroups)
        $spoCtx.ExecuteQuery() 

        Write-Host "Groups Count= $($spGroups.Count)"

        foreach($spGroup in $spGroups)
        { 
            $site =@()
            $users = $spGroup.Users
            $spoCtx.Load($spGroup)
            $spoCtx.Load($users)
            $spoCtx.ExecuteQuery()

            foreach($spUser in $users)
            { 
                try
                {
                    $spoCtx.Load($spUser)
                    $spoCtx.ExecuteQuery()

                    $site += New-Object -TypeName PSObject -Property @{
                                    SiteUrl =$sSiteUrl
                                    GroupName = $spGroup.Title
                                    PrincipalType= $spGroup.PrincipalType
                                    User =$spUser.LoginName
                                    UserEmail =$spUser.Email
                                    } | Select  SiteUrl,GroupName,PrincipalType,User,UserEmail


                }
                catch [System.Exception] 
                { 
                    Write-Host -ForegroundColor Red $_.Exception.ToString()    
                }    


            } 

            $site| Export-CSV ("C:\"+$FileName+".csv") -NoTypeInformation -Append #-Encoding UTF8          

        }       

        Read-Host -Prompt "file created Successfull..! Press any key to close this window"

    } 
    catch [System.Exception] 
    { 
        Write-Host -ForegroundColor Red $_.Exception.ToString()    
        Read-Host -Prompt "Operation failed..! Press any key to close this and re run the script"
    }     
} 


$FileName= "ReportName"          
$sSiteUrl = "https://domain.sharepoint.com"  
$sUserName = "[email protected]" 
$sPassword = ConvertTo-SecureString "YourPassword" -AsPlainText -Force 


Write-Host "Getting Site Collection group Members"
Write-Host "-----------------------------------" 
Get-SiteGroup-Members -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword  -FileName $FileName
2
  • Thanks for the script. When I run it, having plugged in our info, I get this: PS C:\> Get-O365GrpMembers2 Getting Site Collection group Members ----------------------------------- System.Management.Automation.PSArgumentException: Cannot find type [Microsoft.SharePoint.Client.ClientContext]: verify that the assembly containing this type is loaded. at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord) Operation failed..! Press any key to close this and re run the script:
    – Jono
    Commented May 1, 2018 at 18:57
  • Looking more closely at your script, it looks like it's designed to list O365 groups and their members (along with other info about each member), though I will admit I don't understand all of it. I am looking for a way to list all of the SP permissions groups and their members, not O365 groups. Does that make sense?
    – Jono
    Commented May 1, 2018 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.