Create a List View with PowerShell

1. Grab the GUID of the List. Simple way to do it is to go your existing List you want to create the view in, click the “Create View” button (but don’t actually create it in the UI) and copy the value of the ListID querystring variable. You then need to clean it up a bit. For example, take the bold portion of the following URL:


Take the extracted string and delete the portions in red, which are the first and last three characters (which are the HTML encoded characters { and } respectively), and replace the instances of %2D in green (HTML encoded characters to indicate a blank space) with a single blank space .


So we are left with the string 8DF8879E 5046 BCBD 50C4777AF50D , which is a properly formatted GUID and is your List ID.

2. Plunk the following script into a new text file called CreateListView.ps1 and put it on your SharePoint server:

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null
# reading command line arguments
$siteURL = $args[0]
$strViewName = $args[1]
$ListGUID = $args[2]
# enter your CAML query for the view here...
$strQuery = "0"
# create a new SPsite object and recursively go through all webs
# until a matching list GUID is found
$site=new-object Microsoft.SharePoint.SPSite($siteURL)
foreach ($web in $site.AllWebs)
foreach ($list in $web.Lists)
$ListTempGUID = $list.ID.ToString()
if ($ListTempGUID.Contains($ListGUID))
write-host "************"
write-host "Match has been found. Preparing to create a view: ", $strViewName
write-host "List Title: ", $list.Title
write-host "List GUID: ", $list.ID
$fields = $list.Views["All Items"].ViewFields.ToStringCollection()
$result = $list.Views.Add($strViewName, $fields, $strQuery, 100, $True, $False , "HTML", $False)
write-host "View ", $strViewName , " was created successfully."
write-host "Done."

3. To execute the PowerShell, go to your PowerShell command line and execute the following. Note that you need to replace the following sections in green:

– “your_site_collection_URL” with the URL of your site collection e.g. “”
– the “TestView” with your new list name
– the ListID GUID with the List GUID we just extracted

powershell CreateListView.ps1 “your_site_collection_URL” “TestView” “List GUID 8DF8879E 5046 406D BCBD 50C4777AF50D

Comments (3)

  • As you’re using PowerShell, why not get the GUID from the list object directly, i.e. $list.ID


    • You are absolutely correct, getting the List ID via PowerShell is an option and easier. At the time I guess I thought it useful that people recognize the connection between the querystring ID and the back-end ListID.

Leave a Reply

Your email address will not be published. Required fields are marked *