Ensure_SiteColumn_OfType_Calculated_Formula

Language:
PowerShell
Keywords:
SharePoint
Code Snippet

Function Ensure_SiteColumn_OfType_Calculated_Formula( [Microsoft.SharePoint.SPField]$tField
                                                    , [System.String]$tFormula
                                                    ) {
    # Validate that we are using an SPFieldChoice
    if ($tField.GetType() -ne [Microsoft.SharePoint.SPFieldCalculated]) {
        throw New-Object System.ArgumentException([System.String]::Format("Field [{0}] is not of type Calculated", $tField.Title))
    }

    if ($tField.Formula -ne $tFormula) {
        $tField.Formula = $tFormula

        Write-Output([System.String]::Format("Column [{0}] : Setting Formula [{1}]", $tField.Title, $tFormula))
        $tField.Update()
    }

} # Function Ensure_SiteColumn_OfType_Calculated_Formula(...)


Created 2011-10-13
comments powered by Disqus
Login