Tuesday, March 12, 2013

SharePoint PowerShell Create View Based on Existing View

The following PowerShell script crawls the specified lists, copies the fields from the All Items views and creates a new view named "Created By Me" and sets it as default. Tested with SharePoint 2010 but should work with 2013 as well. Tested with list but not with Document Libraries.

I used this script as a base.

$ver = $host | select version
if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} 
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
 Add-PSSnapin "Microsoft.SharePoint.PowerShell"


$web = Get-SPWeb -Identity "http://portal/sites/Requests"
$lists=$web.Lists["User Request", "Hardware Request",  "Employee Request"]
$SourceView="All Items"
$NewViewName="Created By Me"

foreach($list in $lists) {

 $view = $list.Views[$SourceView]
 $Viewfields = $list.Views[$SourceView].ViewFields.ToStringCollection()

# Setting the Query for the View
 $viewQuery = ""
 $viewName = $NewViewName

# Finally – Provisioning the View
 $myListView = $list.Views.Add($viewName, $viewFields, $viewQuery, 100, $True, $False, "HTML", $False)

# You need to Update the View for changes made to the view
# Updating the List is not enough
 $myListView.DefaultView = $True



  1. Hi Tobias,
    i want to update this views with new columns lets say Department and BU, i can do it manually but i have 400 site collections. i want to automate this process powershell,
    any help ?

  2. Please refer my post to create list, fields and view SharePoint list using powershell script:


    Please provide your valuable feedback.

  3. To learn math in playing game than tap to the given game that have the technique to learn cool math in this cool math games junction and your kids love plya nad learn in the math playground.

  4. This comment has been removed by the author.

  5. You are here with the useful program. Programs like this will simplifies the work. This code is like a guide from an expert in essay services free gift . Thanks for sharing.