Dan Sanders
  • Home
  • About
  • Contact
  • – PowerShell
  • – SharePoint
  • – Workflow
Copyright © 2016 Dan Sanders. All Rights Reserved.
Dan Sanders
  • Home
  • About
  • Contact
  • – PowerShell
  • – SharePoint
  • – Workflow

Creating a view for each Document Library in a Site Collection

byDan Sanders inPowershell, SharePoint posted3 February, 2016
135
0
Creating a view for each Document Library in a Site Collection

In this post, I will show you how to create a view for each Document Library or List in a Site Collection or sub-sites of a Web using PowerShell.

1.) Using SharePoint, create a view on a list and select the columns* you want, so that we can grab the view with PowerShell and send it everywhere.
*Make sure that you select columns that are available everywhere that you are wanting to apply this view, else the view will fail to create.

2.) Open SharePoint Management Shell and grab the new view

$Web = Get-SPWeb http://SiteCollection/Web
$List = $Web.GetList("/Web/List")
$NewView = $list.Views["ViewName from Step 1"]

To display the view and its properties:

$NewView

Take note of the ViewFields, these are the columns you selected in step 1.

3.) Create the view on all Document Libraries in a Site Collection

$viewDefaultView = $False

$Site = Get-SPSite http://SiteCollection/
$Webs = $Site.AllWebs

foreach($Web in $Webs)
{
  $Weblists = $Web.Lists
  for ($i = 0; $i -lt $WebLists.Count; $i++)
  {
    $list = $web.Lists[$i];
    $webUrl = $web.Url
    try
    { 
      if($list.BaseTemplate -eq "DocumentLibrary"){
        $CreatedView = $list.Views.Add("QuickEdit View", $newview.viewFields, $NewView.Query, $NewView.RowLimit, $NewView.Paged, $viewDefaultView)
        Write-Host ("View '" + $CreatedView.Title + "' created in list '" + $list.Title + "' on site " + $webUrl) 
      }
    }
    catch
    {
      Write-Host ("There was a problem trying to create the view in the site " + $webUrl + ": " + $web)
    } 
    
  }
}

Notes:
– To apply the view to all lists, not just Document Libraries, remove the IF Statement wrapper.
– To create the view in all Libraries in the SubSites of a Site rather than the Site Collection replace the $Site and $Webs with:

$Site = Get-SPWeb http://SiteCollection/Web/ 
$Webs = $site.webs

– To delete a view in all Libraries by view name, place the following in place of the code within the IF Statement:

$ViewToDEL = $list.Views["View Name"] 
$list.Views.Delete($ViewToDEL.ID)

– To create a view manually in PowerShell check out this blog post

I needed to create a view in all Document Libraries because I did not have a view that did not use Group By, which meant the Quick Edit was always Greyed Out.

Document LibrariesPowerShellQuick EditSharePoint 2010SharePoint 2013Views
Share this :

Related Posts

0
28 April, 2016
Disable Loopback check – UPA Picture Sync Error

In this post, I will show you how to create a view for each Document Library or List in a Site...

73 Comments
7
Enabling multiple Document Set views
20 September, 2017
Enabling multiple Document Set views

In this post, I will show you how to create a view for each Document Library or List in a Site...

3 Comments
0
PowerShell for every List in each Web of a SiteCollection
28 February, 2016
PowerShell for every List in each Web of a SiteCollection

In this post, I will show you how to create a view for each Document Library or List in a Site...

37 Comments
0
SharePoint Foundation 2013 Help-desk System
30 August, 2016
SharePoint Foundation 2013 Help-desk System

In this post, I will show you how to create a view for each Document Library or List in a Site...

No comment
0
Remote PowerShell with SharePoint 2010 Kerberos
31 July, 2013
Remote PowerShell with SharePoint 2010 Kerberos

In this post, I will show you how to create a view for each Document Library or List in a Site...

224 Comments
0
25 June, 2013
Deploying SharePoint 2010 Solutions with Powershell

In this post, I will show you how to create a view for each Document Library or List in a Site...

20 Comments
0
Adding a column to a Content Type (CT) at a library level with PowerShell.
10 February, 2016
Adding a column to a Content Type (CT) at a library level with PowerShell.

In this post, I will show you how to create a view for each Document Library or List in a Site...

67 Comments
0
24 June, 2013
Customizing the Quick Launch

In this post, I will show you how to create a view for each Document Library or List in a Site...

368 Comments
0
Libraries with no Default View
27 January, 2016
Libraries with no Default View

In this post, I will show you how to create a view for each Document Library or List in a Site...

26 Comments
0
Quick Edit button grayed out
3 February, 2016
Quick Edit button grayed out

In this post, I will show you how to create a view for each Document Library or List in a Site...

No comment

Leave a Comment! Cancel reply

You must be logged in to post a comment.

Recent Posts

  • SharePoint Add-in 401 Unauthorized
  • Content Database and Site Collection Report
  • SharePoint helpful hidden URLs

Tags

Config (1) Content Types (2) Design (3) Document Libraries (7) Document Sets (1) How-To (1) Lists (4) Office365 (1) PnP (1) PowerShell (12) Quick Edit (2) REST (1) SharePoint (11) SharePoint 2010 (11) SharePoint 2013 (14) SharePoint Foundation (2) SharePoint Online (1) SP2010 Workflow (2) SP2013 Workflow (3) Systems (2) User Profile Service (1) Views (5) Windows Server (1) Workflow (2)

Archives

  • November 2020
  • December 2018
  • September 2018
  • July 2018
  • September 2017
  • August 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • September 2013
  • July 2013
  • June 2013