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