Add existing content type directly to SPO list using Powershell

A short script to add an existing site content type directly to a SharePoint Online list. The script is fully described in an article here:  http://social.technet.microsoft.com/wiki/contents/articles/31051.sharepoint-online-content-types-in-powershell.aspx

 
 
 
 
 
(0)
1,135 times
Add to favorites
Office 365
5/20/2015
E-mail Twitter del.icio.us Digg Facebook
  • Unknown Error
    4 Posts | Last post November 13, 2016
    • Hello,
      
      I tried using script to add a existing content type to one of the document library, but I am getting "Unknown Error" on "Execute Query" call within try block. 
      
      Any idea what is the possibility?
      
      Thanks,
      Shashi
    • Hi,
      
      Thank you for using the script. Unknown error is a very general message. 
      1. Are you using the correct list title? Do you receive the same error with another list?
      2. Are you using the correct content type id? Do you receive the same error with another content type?
      3. Is the content type on the same site as the list? Can you add it manually?
      
      I will be looking forward to your answer.
      Regards, 
    • Hello Shashi,
      I had the same problem and I changed this line from:
      $contentType=$ctx.Web.ContentTypes.GetById($ContentTypeID)
      to
      $contentType=$ctx.Site.RootWeb.ContentTypes.GetById($ContentTypeID)
      and it worked!
      Hope it helps
      Thanks
    • Thanks beckham_girl. 
      I am sure it will be helpful to other users.