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
30
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
Enable Fly-Out for Quick Launch

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

96 Comments
0
17 September, 2013
Remove Drop Off Library and fix up the QuickLaunch in SharePoint 2010

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

67 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.

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

67 Comments
0
Remote PowerShell with SharePoint 2010 Kerberos
31 July, 2013
Remote PowerShell with SharePoint 2010 Kerberos

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

224 Comments
0
24 June, 2013
Customizing the Quick Launch

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

368 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...

54 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

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

37 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
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...

135 Comments
0
Associate your 2013 workflow to every library/list through PowerShell
29 February, 2016
Associate your 2013 workflow to every library/list through PowerShell

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

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