I need some assistance with a task I would like to complete. I want to able to change (correct) the Content Type View settings for all SPWeb in SPSites. I can do this on a per SPWeb basis but would like to all at once.
SP2010 no longer has the ‘group by content type’ option availbale for list views. So to add this functionality back to list/libraries you can use SPDesigner and add the following Query properties directly to the view:
<Query><GroupBy Collapse=”TRUE” GroupLimit=”100″><FieldRef Name=”Content Type”/></GroupBy></Query>
Or, you can use PowerShell, which I have done:
param( [string]$WebURL, [string]$listName )
$web = Get-SPWeb $WebURL;
$list = $web.Lists[$listName];
$view = $list.Views[“By Content Type”];
$view.Query = “<GroupBy Collapse=’TRUE’ GroupLimit=’100′><FieldRef Name=’ContentType’/></GroupBy>”;
$view.Update();
$web.Dispose();
I am still a beginner at PowerShell and need so guidance on how to Loop through all of my SPWeb objects for any given SPSite. I would still like to use my parameters as well. Any help with explanation would be greatly appreciated…
Good Post Jason.
I have tested it on SP 2013 also and here also working fine.
Just for others( I was also a bit confused)
$view = $list.Views[“By Content Type“]; replaced by the View name where you want to use the GroupBy Clause.
Adding $view.Scope = [Microsoft.SharePoint.SPViewScope]::Recursive to the script worked for me.. Consider this one solved.
Not tested.. but checkout those links:
http://sharepointnadeem.blogspot.ca/2012/02/create-view-to-show-all-items-without.html
http://www.sharepointben.com/blog/lists/posts/615#.UtbyrPRDvVs