Wednesday, December 30, 2015

Add Column to View in SharePoint using PowerShell

How to add a column to SharePoint list view using PowerShell?

PowerShell Script to add a field to View:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#configuration parameters
$ListName="Project Milestones"
$ViewName="All Items"

Function Add-FieldToView([Microsoft.SharePoint.SPList]$List, [String]$ViewName, [string]$FieldInternalName)
    #Get the view
    $View = $List.Views[$ViewName]
    #To Get the Default View: List.DefaultView
    if($view -eq $Null) {write-host "View doesn't exists!" -f Red; return}
    #Check if view has the specific field already!
        #To Delete a field from view: $View.ViewFields.delete($FieldInternalName)
        write-host "Field added to View!" -f Green
        write-host "Field Already Exists in the view!" -f Red

#Get the Web and List
$Web= Get-SPWeb $WebURL
$List = $web.Lists.TryGetList($ListName)

#If List Exists
if ($List )
    #Call the function
    Add-FieldToView $List $ViewName $FieldInternalName

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...