Delete SharePoint list view and set a list view as default view using PowerShell

This SharePoint PowerShell tutorial explains, how to delete a SharePoint list view using PowerShell and also how to set a SharePoint list view as the default view for the SharePoint list using PowerShell.

The PowerShell script to delete SharePoint list view and set list view as default SharePoint list view will work in SharePoint 2013/2016.

We can write, debug and test the PowerShell script in Windows PowerShell ISE or Visual Studio code.

Delete SharePoint list view using PowerShell

Here, in this case, I have a Test list which has a Test view, I want to delete this SharePoint list through PowerShell.

Below is the PowerShell command to delete a list view using PowerShell:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$web = Get-SPWeb "http://win-pfcp2dgt8di/sites/EnjoySharePoint/"
$list = $web.GetList("http://win-pfcp2dgt8di/sites/EnjoySharePoint/Lists/MyTestList1/")
$myview = $list.Views["MyTestView"]
$list.Views.Delete($myview.id)
$web.Dispose()

Once you run the above PowerShell script, the “MyTestView” list view will get delete from the SharePoint list.

Set SharePoint List View as Default view using PowerShell

We can also set a view as the default SharePoint list view by using PowerShell. Here I have a view name as “MyTestDefaultView” and below is the PowerShell command to set it as default view:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$web = Get-SPWeb "http://win-pfcp2dgt8di/sites/EnjoySharePoint/"
$list = $web.GetList("http://win-pfcp2dgt8di/sites/EnjoySharePoint/Lists/MyTestList1/")
$view = $list.Views["MyTestDefaultView"]
$view.DefaultView = $true
$view.Update()

Once you run the above PowerShell Script, it will set the MyTestDefaultView as the default view for the SharePoint list.

You may like following PowerShell SharePoint tutorials:

Hope, this SharePoint PowerShell tutorial helps to learn how to delete List View using PowerShell in SharePoint 2013/1016. And also it helps to Set List View as Default view using PowerShell SharePoint 2013/2016.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>