Ensure_View_Column

Language:
PowerShell
Keywords:
SharePoint
Code Snippet

## Ensures that an SPView contains a specific SPField (no order is guaranteed).. if it does, do nothing; if it does not, add it
Function Ensure_View_Column( [Microsoft.SharePoint.SPView]$tView
                           , [Microsoft.SharePoint.SPField]$tField) {
    if (!$tView.ViewFields.Exists($tField.InternalName)) {
        Write-Output([System.String]::Format("List [{0}] : View [{1}] : Adding Column [{2}]", $tView.ParentList.Title, $tView.Title, $tField.Title))
        $tView.ViewFields.Add($tField)
        $tView.Update()
    }
} # Function Ensure_View_Column(...)


Created 2011-10-13
comments powered by Disqus
Login