SharePoint Online: PowerShell kullanarak İçerik Türlerinde Site Sütunu Kullanımını Bulma


Gereksinim: SharePoint Online site koleksiyonundaki İçerik Türü'nde Site Sütunu Kullanımını bulun.

Küçük bir arka plan: SharePoint Online'da bir site sütununu silmeye çalışırken şu hata mesajını aldım: “içerik türlerine dahil olan site sütunları silinemez. Silmeden önce bu site sütununa yapılan tüm referansları kaldırın”.

Peki bir site sütununun nerede kullanıldığını nasıl bulabilirim?

İçerik Türlerinde Site Sütunu kullanımını Bulmak için PowerShell:

Bu PowerShell betiği, sitedeki tüm içerik türlerinde döngü yapar, belirli site sütununun herhangi birinde referans alınıp alınmadığını kontrol eder ve sonucu verir.


#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 

Bu komut dosyası tüm içerik türlerini tarar ve sonuçları yazdırır:

İlgili makaleler