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

Adding a ContentType to each Library with PowerShell

byDan Sanders inPowershell, SharePoint posted4 February, 2016
0
0

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all Libraries of sub-sites of a particular site.
My CT has already been created using the UI at Site Collection > Site Settings > Content Types
Running the below PowerShell code in the SharePoint Management Shell solved my problem.

$site = Get-SPSite http://intranet
$CTtoAdd = $site.RootWeb.ContentTypes["RDC_Link to Document"]
$Web = Get-SPWeb http://intranet/Web/
$Web.webs | ForEach-Object {
 $_.title
 $_.webs.lists | where { $_.BaseTemplate -eq "DocumentLibrary" } | ForEach-Object {
 #I used $_.Webs.Lists above to target the 3rd level down (i.e. http://intranet/Web/Web/Web)
 if($_.title -eq "Site Assets")
  {
   write-host "Skip Site Assets"
  }
  else
  {
   try
   {
    $ct = $_.ContentTypes.Add($CTtoAdd)
    write-host "Content type" $ct.Name "added to list" $_.Title
    $_.Update()
   }
   catch
   {
    write-host "Failed to add Content type" $ct.Name "to list" $_.Title
   }
  }
 }
}
$Site.Dispose()
$Web.Dispose()

If you wanted to add the CT on all Libraries in your Site Collection you would replace the first 5 lines to the following:

$CTtoAdd = $site.RootWeb.ContentTypes["RDC_Link to Document"]
$Site = Get-SPSite http://SiteCollection/
$site | Get-SPWeb -Limit all | ForEach-Object {
$_.title
$_.lists | where { $_.BaseTemplate -eq "DocumentLibrary" } | ForEach-Object {

To delete CT’s and for other ways to add them, check out this blog post

Content TypesDocument LibrariesPowerShellSharePointSharePoint 2010SharePoint 2013
Share this :

Related Posts

0
24 June, 2013
Customizing the Quick Launch

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

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

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

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

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

No comment
2
SharePoint Foundation 2013 Shopping Cart
30 August, 2016
SharePoint Foundation 2013 Shopping Cart

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

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

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

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

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

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

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

1 Comment
0
28 February, 2016
Publish SharePoint 2013 Workflow Globally

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

83 Comments
0
Fix SharePoint 2013 UPS Stuck on Starting
4 July, 2018
Fix SharePoint 2013 UPS Stuck on Starting

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

170 Comments
0
Creating a view for each Document Library in a Site Collection
3 February, 2016
Creating a view for each Document Library in a Site Collection

I needed to add the custom Content Type (CT) “RDC_Link to Document” to all...

No comment

Leave a Comment! Cancel reply

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

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