Hi Bailey, John, for members, visitors. You can access the groups of members and visitors through the Get-SPOSiteGroup cmdlet and get the users in them. The following is a script for reference:
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking
#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminName = "spadmin@crescent.com"
$SiteURL = "https://crescent.sharepoint.com/sites/sales"
$CSVPath = "C:\Users\Administrator\Desktop\GroupsReport.csv"
#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 $Credentialexp
$GroupsData = @()
#get all sharepoint online 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
$GroupsData += New-Object PSObject -Property @{
'Site URL' = $SiteURL
'Group Name' = $Group.Title
'Users' = $Group.Users -join ","
}
}
$GroupsData | Export-Csv $CSVPath -NoTypeInformation
![Screenshot 2023-06-27 160742](https://learn-attachment.microsoft.com/api/attachments/a6a95927-c5ce-4921-8ae6-ba24f866aa2e?platform=QnA)
And for guests, you can use the cmdlet Get-SPOExternalUser:
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking
#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminName = "spadmin@crescent.com"
$SiteURL="https://crescent.sharepoint.com/sites/sales"
$CSVPath = "C:\Users\Administrator\Desktop\GuestsReport.csv"
#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 $Credentialexp
$GroupsData = @()
#get all sharepoint online groups
$Guests = Get-SPOExternalUser
#Get Members of each group
foreach($Guest in $Guests)
{
$GroupsData += New-Object PSObject -Property @{
'Site URL' = $SiteURL
'Guest' = $Guest.DisplayName
}
}
$GroupsData | Export-Csv $CSVPath -NoTypeInformation
![User's image](https://learn-attachment.microsoft.com/api/attachments/40b8d3ba-2d1f-41c8-9798-6930d31cc0e8?platform=QnA)
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.