Create and delete SharePoint list views with PowerShell

Here’s how you can create and delete views in a SharePoint list or library using PowerShell (Is there anything that can’t be done through a PowerShell script?)

The script below creates a view called “TestView”. It expects three command-line arguments: site collection URL, the name of the view to create, and the list GUID. The view that’s created is an exact replica of the “All Items” view (you can certainly modify the code as needed). Here’s how you would call this script from the command line:

Finally, how do you find out the GUID of your list? It’s fairly straightforward – you just need to access the SPList.ID property of your list. Here’s a simple script that will output the GUIDs of all lists in your site collection: