Saturday, January 16, 2016

SharePoint Online: Enable Content Types using PowerShell

How to Enable Content Types in SharePoint Online?

  • Go to List >> List Settings >> Advanced Settings
  • Set "Yes" for "Allow management of content types?" and hit OK button to save your changes.
    enable content types in sharepoint online
If you go back to list settings, you'll find a section "Content Types" with the particular list or library's default content type listed (E.g. Item for custom list!). You an add any existing content types to the list now!

PowerShell to Enable Content Types in SharePoint Online List using PowerShell:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#function to turn ON Content Type in SharePoint Online list or library
Function Enable-ContentTypes()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        #Get the List object
        $List = $Ctx.Web.Lists.GetByTitle($ListName)

        #Check if content types are already enabled
        If($List.ContentTypesEnabled -eq $True)
            Write-host "Content Types Already Enabled in the given List!" -ForegroundColor Yellow
            #enable content types in the list

            Write-host "Content Types Enabled for given List Successfully!" -ForegroundColor Green  
    Catch {
        write-host -f Red "Error enabling Content Type!" $_.Exception.Message

#Set parameter values

#Call the function
Enable-ContentTypes -SiteURL $SiteURL -ListName $ListName

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...