Monday, November 30, 2015

Remove Field from View using PowerShell in SharePoint

In SharePoint, If you want to remove field from view programmatically using PowerShell, Here you go:

SharePoint delete column from view using PowerShell:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#Function: sharepoint powershell delete field from view
Function Remove-FieldFromView([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!
    if($view.ViewFields.ToStringCollection().Contains($FieldInternalName))
    {
        #Remove field from view: 
        $View.ViewFields.delete($FieldInternalName)
     $View.Update()
     write-host "Field Removed from the View!" -f Green
    }
    else
    {
    write-host "Field Doesn't Exists in the view!" -f Red
    }
}

#configuration parameters
$WebURL="https://portal.crescent.com/projects/"
$ListName="Project Milestones"
$ViewName="All Items"
$FieldName="ProjectDescription"

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

#Call the function to remove column from view 
Remove-FieldFromView $List $ViewName $FieldName

This PowerShell script removes given field from the given view.



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


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...