Tag Archives: Group Information

Retrieve SharePoint Site Groups Information Using PowerShell

A colleague asked me a script to retrieve SharePoint Site Groups information by excluding the user’s information and added he couldn’t use Select-Object cmdlet to exclude user’s collection in the group property. Yes, it’s not possible! But, we have a fix for it and here is the PowerShell script to get Group properties by ignoring the UserCollection property in it

Import-Module C:\Users\904870.CORPORATEROOT\Documents\WindowsPowerShell\Modules\xMicrosoft.SharePointOnline.PowerShell\Microsoft.SharePoint.Client.dll
$UserName = "chendrayan@contoso.com"
$Credential = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force
$ctx = [Microsoft.SharePoint.Client.ClientContext]::new("https://contoso.sharepoint.com")
$ctx.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($UserName,$Credential)
$Groups = $ctx.Web.SiteGroups
$Props = ([Microsoft.SharePoint.Client.Group].GetProperties() | ? {$_.PropertyType -notlike '*Collection*'}).Name 
foreach($Group in $Groups)
    [Microsoft.SharePoint.Client.Group]$Group | Select -Property $Props

Reason: We need to explicit request and execute to get user collection information but in our case it’s not required. So, simply we skipped the property which has type as collection. Note: In group property user is the only collection type property.