Ensure_SiteColumn_OfType_Choice_Contains

Language:
PowerShell
Keywords:
SharePoint
Code Snippet

Function Ensure_SiteColumn_OfType_Choice_Contains( [Microsoft.SharePoint.SPField]$tField
                                                 , $tChoice
                                                 ) {
    if ($tField.GetType() -ne [Microsoft.SharePoint.SPFieldChoice]) {
        throw New-Object System.ArgumentException([System.String]::Format("Field [{0}] is not of type Choice", $tField.Title))
    }
    
    if (!$tField.Choices.Contains($tChoice)) {
        $tField.Choices.Add($tChoice) | Out-Null
        Write-Output([System.String]::Format("Field [{0}] : Adding Choice [{1}]", $tField.Title, $tChoice))
        $tField.Update()
    }
} # Function Ensure_SiteColumn_OfType_Choice_Contains(...)


Created 2011-11-22
comments powered by Disqus
Login