SharePoint Online:使用 PowerShell 在列表和库中查找网站列使用情况
要求:在 SharePoint Online 网站集中查找网站列用法。
SharePoint Online:用于获取网站列在网站集的列表和库中的使用情况的 PowerShell:
您是否想要查找 SharePoint Online 列表和库中使用特定列的位置? PowerShell 可以提供帮助!此博文将向您展示如何使用 PowerShell 查找 SharePoint Online 网站中的网站栏使用情况。这有助于了解网站栏在您的环境中的使用方式以及识别任何潜在问题。
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Function to get a particular Site column usage in Lists and Libraries
Function Find-SPOSiteColumnUsage([String]$SiteURL, [String]$SiteColumnInternalName)
{
Try{
Write-host -f Yellow "Processing Site:" $SiteURL
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get All Lists and Libraries of the Web
$Ctx.Load($Ctx.Web)
$Ctx.Load($Ctx.Web.Webs)
$Ctx.Load($Ctx.Web.Fields)
$Ctx.Load($Ctx.Web.Lists)
$Ctx.ExecuteQuery()
#Get the site column
$SiteColumn = $Ctx.Web.Fields | where {$_.InternalName -eq $SiteColumnInternalName}
if($SiteColumn -ne $NULL)
{
#Loop through each List Field
ForEach($List in $Ctx.Web.Lists)
{
Write-host -f Yellow "`t `t Scanning List $($List.Title)"
$Ctx.Load($List.Fields)
$Ctx.ExecuteQuery()
ForEach($Field in $List.Fields)
{
If($Field.Id -eq $SiteColumn.id)
{
Write-host -f Green "`t `t Found the Site Column in List '$($List.Title)' at Site '$($SiteURL)'"
}
}
}
}
#Iterate through each subsite of the current web
foreach ($Subweb in $Ctx.web.Webs)
{
#Call the function recursively
Find-SPOSiteColumnUsage $Subweb.url $SiteColumnInternalName
}
}
Catch {
write-host -f Red "Error Generating Site Column Usage Report!" $_.Exception.Message
}
}
#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$SiteColumnInternalName="TotalInvestment"
#Get Credentials to connect
$Cred= Get-Credential
#Call the function to get the Site Column usage
Find-SPOSiteColumnUsage $SiteURL $SiteColumnInternalName
该脚本获取列表和库中特定网站栏的使用情况并打印结果,如下所示:
当计划删除或重命名网站栏或对网站栏问题进行故障排除时,这非常有用。
