我收到了一项请求,要求检查哪些 SharePoint 网站将私有设置为私有和公共。
这是我正在使用的 PowerShell 脚本。
遗憾的是,当我打开 .csv 文件时,它显示所有网站都是公开的。但在 SharePoint Online 中,当我转到 SharePoint 管理中心->活动站点->站点名称->设置 某些站点将隐私设置为私有。
如何编辑以下脚本以输出哪些网站的隐私设置为私人和公共?
# 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
使用以下 pnp powershell 获取 SharePoint 中的所有公共或私有站点:
$AdminCenterURL = "https://yourtenant-admin.sharepoint.com"
#Get Credentials to connect
$Cred = Get-Credential
#Connect to Tenant Admin
Connect-PnPOnline -URL $AdminCenterURL -Credential $Cred
Get-PnPMicrosoft365Group -IncludeSiteUrl | Select Displayname,Visibility,siteurl
如果答案对你有帮助,请点击答案左侧的“√”并点赞。