Remove Field from View using PowerShell in SharePoint
How to Remove Column from View in SharePoint?
Do you want to remove a column from your view in SharePoint? In this guide, we’ll show you how to delete a field from your list view using the web interface and PowerShell.
- Browse to your list or library in SharePoint >> Click on the List or Library tab from ribbon.
- Click on the “Modify View” button under the “Manage Views” group.
- In the Edit View page, uncheck the column(s) you wish to remove from the particular View.
- Click OK to save.
If you want to remove a field from view programmatically using PowerShell, Here you go:
SharePoint delete column from view using PowerShell:
So if you’ve got a column in the view, you don’t need anymore? Here is the PowerShell to remove a column from view.
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]
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 the given field from the given view.
Remove Column from default view in SharePoint using PowerShell:
To remove the column from the default view, just change the line.
$View = $List.Views[$ViewName]
To:
$View: List.DefaultView
This worked a treat thank you!