Requirement: Generate a report with all site groups and members of each group of a SharePoint online site collection.
Get all Site Groups and Members of Each group:
Get all Site Groups and Members of Each group:
#Variables for processingTo get all users of the site collection, use:
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminName = "spadmin@crescent.com"
$SiteURL="https://crescent.sharepoint.com/sites/sales"
#User Names Password to connect
$Password = Read-host -assecurestring "Enter Password for $AdminName"
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password
#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential
#Get all Site groups
$SiteGroups = Get-SPOSiteGroup -Site $SiteURL
#Get Members of each group
foreach($Group in $SiteGroups)
{
Write-host "Group:"$Group.Title
Get-SPOSiteGroup -Site $SiteURL -Group $Group.Title | Select-Object -ExpandProperty Users
}
Get-SPOUser -Site $siteURL | select DisplayName, LoginName | Where { $_.LoginName -like "*@crescent.com"}