I received a request to check what SharePoint sites have private set to private and public.
This is the PowerShell script that I am using.
Sadly, when I open the .csv file, it says all of the sites are public. But in SharePoint online, when I go to SharePoint Admin Center->Active sites->Site name->Settings some sites have privacy set to private.
How do I edit the below script to output what sites have privacy set to private and public?
# Connect to SharePoint Online
Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite -UseWebLogin
# Get all sites within the SharePoint Online tenant
$sites = Get-PnPTenantSite
# Initialize an array to store site privacy information
$sitePrivacyReport = @()
# Iterate through each site
foreach ($site in $sites) {
$siteUrl = $site.Url
$siteTitle = $site.Title
# Get site properties to check if it's public or private
$siteProperties = Get-PnPTenantSite -Url $siteUrl
$privacyStatus = $siteProperties.Status
# Determine if the site is public or private
if ($privacyStatus -eq "Active") {
$privacy = "Public"
} else {
$privacy = "Private"
}
# Add site information to the report array
$siteInfo = New-Object PSObject -Property @{
SiteTitle = $siteTitle
SiteUrl = $siteUrl
Privacy = $privacy
}
$sitePrivacyReport += $siteInfo
}
# Define the output path
$outputPath = "C:\Users\USERNAME\Downloads\SharePoint_Site_Privacy_Report.csv"
# Export the report to a CSV file
$sitePrivacyReport | Export-Csv -Path $outputPath -NoTypeInformation
Write-Host "Report saved to: $outputPath"
# Disconnect from SharePoint Online
Disconnect-PnPOnline
Using the following pnp powershell to get All the Public or Private Sites in SharePoint :
Output:
If the answer is helpful, please click "√" on the left panel of the answer and kindly upvote it.