Forum Discussion

tomwrigglesworth's avatar
tomwrigglesworth
Copper Contributor
Dec 19, 2024

Creating an exported report of members

# Define the tenant $tenant = "testing" # Ensure the output directory exists $outputDir = "C:\temp" if (-Not (Test-Path -Path $outputDir)) { New-Item -Path $outputDir -ItemType Directory } # Connect to SharePoint Online try { Connect-SPOService -Url "https://$tenant-admin.sharepoint.com" Write-Host "Connected to SharePoint Online." } catch { Write-Host "Failed to connect to SharePoint Online: $_" exit } # Get all site collections try { $sites = Get-SPOSite -Limit All Write-Host "Retrieved site collections." } catch { Write-Host "Failed to retrieve site collections: $_" exit } # Loop through each site foreach ($site in $sites) { try { # Get the current date and time $dateTime = Get-Date -Format "yyyyMMdd_HHmmss" # Define the site URL $siteUrl = $site.Url # Get the users and export to CSV $users = Get-SPOUser -Site $siteUrl if ($users) { $filePath = "$outputDir\$($site.Title)-$dateTime.csv" $users | Select-Object * | Export-Csv -Path $filePath -NoTypeInformation Write-Host "Exported users for site $($site.Title) to $filePath." } else { Write-Host "No users found for site $($site.Title)." } } catch { Write-Host "Failed to process site $($site.Url): $_" } } Write-Host "Export completed for all sites."

  • Hello tomwrigglesworth 

     

    maybe this thread can help you: https://learn.microsoft.com/en-us/answers/questions/1312309/using-powershell-can-i-list-all-members-visitors-a?WT.mc_id=DX-MVP-5004845

     

    Best, Dave

Resources