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 the 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:
- Delete SharePoint list using PowerShell
- Delete content type from SharePoint list using PowerShell
- PowerShell SharePoint Commands
- How to activate publishing feature in SharePoint 2013/2016 using PowerShell Script
- 3 Different ways to Change Site Collection URL in SharePoint 2013/2016 using PowerShell
- PowerShell Script to deploy WSP Solution in SharePoint 2013
- 15 PowerShell Basic Commands Examples
- Working with PowerShell in SharePoint Online/2016/2013
- Working with PowerShell Variables
I 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.
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com
Download SharePoint Online Tutorial PDF FREE!
Get update on Webinars, video tutorials, training courses etc.