Tìm kiếm trang web

SharePoint Online: Tìm cách sử dụng cột của trang trong các loại nội dung bằng PowerShell


Yêu cầu: Tìm cách sử dụng cột của trang trong Loại nội dung trong tuyển tập trang SharePoint Online.

Thông tin cơ bản: Khi cố gắng xóa một cột trang trong SharePoint Online, nhận được thông báo lỗi: “không thể xóa các cột trang được bao gồm trong loại nội dung. Hãy xóa tất cả các tham chiếu đến cột trang web này trước khi xóa nó”.

Vì vậy, Làm cách nào để tìm thấy cột trang web đang được sử dụng ở đâu?

PowerShell để tìm cách sử dụng Cột trang web trong các loại nội dung:

Tập lệnh PowerShell này lặp qua tất cả các loại nội dung trong trang web, kiểm tra xem cột trang web cụ thể có được tham chiếu trong bất kỳ loại nội dung nào trong số đó hay không và đưa ra kết quả.


#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 content types 
Function Get-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 Content Types of the Web
        $Ctx.Load($Ctx.Web)
        $Ctx.Load($Ctx.Web.Webs)
        $ContentTypes = $Ctx.web.ContentTypes
        $Ctx.Load($ContentTypes)
        $Ctx.ExecuteQuery()

        #Leave Hidden content types
        $ContentTypes = $ContentTypes | Where {$_.Group -ne "_Hidden"}
        Write-host -f Yellow "`t Found $($ContentTypes.count) Content Types"

        #Loop through each content types Field
        ForEach($ContentType in $ContentTypes)
        {
            Write-host -f Yellow "`t `t Scanning Content Type $($ContentType.Name)"
            $Ctx.Load($ContentType.Fields)
            $Ctx.ExecuteQuery()

            ForEach($Field in $ContentType.Fields)
            {
                If($Field.InternalName -eq $SiteColumnInternalName)
                {
                    Write-host -f Green "`t `t Found the Site Column in Content Type '$($ContentType.Name)' at Site '$($SiteURL)'"
                }
            }
        }

        #Iterate through each subsite of the current web
        foreach ($Subweb in $Ctx.web.Webs)
        {
            #Call the function recursively
            Get-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 content type usage
Get-SPOSiteColumnUsage $SiteURL $SiteColumnInternalName 

Tập lệnh này quét tất cả các loại nội dung và in kết quả:

Bài viết liên quan