PowerShell'i kullanarak SharePoint Listesindeki Hesaplanan Sütun Formülünü Güncelleme


Gereksinim: Site koleksiyonunun tamamındaki bir listenin belirli bir sütunu için Hesaplanan Alanın formülünü güncelleyin.

SharePoint'te hesaplanan alan formülünü güncellemek için PowerShell:

Bu, site koleksiyonundaki tüm alt siteler için site sütununun formülünü günceller.


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Variables
$SiteURL = "https://intranet.crescent.com"
$ColumnName="Productivity"

#Iterate through each web in the given site collection
$Webs = Get-SPSite $SiteURL | Get-SPWeb -Limit All | ForEach-Object {
    
    #Check if the column exists
    if($_.Fields.ContainsField($ColumnName))
    {
        $column = $web.Fields[$ColumnName]
        #Update calculated field formula
        $Column.Formula = "=(([PlannedEffort]/5)/ActualEffort)*8"
        $Column.update($true)
        write-host "Updated Calculated Field formula at $($_.URL)"
    }
}

Aynı kod Liste düzeyindeki formüller için de kullanılabilir.

SharePoint Listesindeki Hesaplanan Sütun formülünü Güncellemek için PowerShell:

Başka bir durumda hesaplanan sütunun formülündeki bir alanı tüm siteler için değiştirmek zorunda kaldık.


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$SiteURL = "https://intranet.crescent.com"
$ListName="Projects"
$ColumnName="Productivity"
$OldField="PlannedEffort"
$NewField="EstimatedHours"

#Iterate through each web in given site collection
$Webs = Get-SPSite $SiteURL | Get-SPWeb -Limit All | ForEach-Object {
    
    #Get the List
    $List = $_.Lists.TryGetList($ListName)

    If($List)
    {
        #Check if the column exists
        if($List.Fields.ContainsField($ColumnName))
        {
            $Column = $List.Fields[$ColumnName]
            #Update calculated field formula
            $Column.Formula = $Column.Formula.Replace($OldField,$NewField)
            $Column.update($true)
            write-host "Updated Calculated Field formula at $($_.URL)"
        }
    }
} 

PowerShell kullanarak hesaplanan alan oluşturma başka bir makalede anlatılmaktadır: PowerShell Kullanarak SharePoint Listesine Hesaplanan Sütun Nasıl Eklenir?

İlgili makaleler