I need to add a content type whenever an Asset Library is provisioned. How can I do this ? We have SharePoint 2016 On-Prem

Regards, Bismarck


here is the script, change the $Site, $ListName, $ContentTypeName:

asnp *sharepoint*

$Site = Get-SPSite https://sharepoint.dev.cz
$ListName = "Site Assets"
$ContentTypeName = "Picture"

$Web = $Site.OpenWeb()    
Write-Host "Checking site:" $Web.Title
$docLibrary = $Web.Lists[$ListName]

    if ($docLibrary -ne $null)
        $docLibrary.ContentTypesEnabled = $true
        $ctToAdd = $Web.ContentTypes[$ContentTypeName]
        $ct = $docLibrary.ContentTypes.Add($ctToAdd)
        Write-Host "Content type" $ct.Name "added to list" $docLibrary.Title
        Write-Host "The list" $ListName "does not exist in site" $Site.Title
  • I was hoping for something like a List Template ID, because users may provision an Asset Library under a different "Title" (List Name) such as "My Asset Library". I cannot find a List Template ID for "Asset Library" – Bismarck Jan 17 at 14:35
  • I look at properties and Site Assets library is classic Document Library, ServerTemplate="101" ;BaseTemplate: DocumentLibrary ;TemplateFeatureId: 00bfea71-e717-4e80-aa17-d0c71b360101. So is impossible to filter by DocumentTemplateID here. Site Assets library is different from another Document Library only by name. So you are not able to create Site Asset Libary with different Title, cause this is classic Document Library. – Zdeněk Vinduška Jan 17 at 14:44
  • I was able to create an Asset Library and name it "My Asset Library" However, I think the Template ID is 851. I will try that and see. – Bismarck Jan 17 at 14:54
  • Try it, I worked with SP2013 and here I have AL like DOcumentLibrary and Images as 851. I find article about it but they wrote about SP2010 and there were lots of differences between 2010 and 2013. Hope it helps. Make it as answer, thanks. – Zdeněk Vinduška Jan 17 at 14:58
  • You are correct. When I ran through the debugger, it reported the List ID as 101 (DocumentLibrary {101}). – Bismarck Jan 17 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.