SharePoint Online: Update Content Type using PowerShell

Requirement: Update content type settings in SharePoint Online using PowerShell

How to Update Content Type Settings in SharePoint Online?
To editing content type's general settings such as name, description, and group information, follow these steps:
  1. Navigate to the SharePoint Online site where the content type was created.
  2. Click on Settings >> Site Settings
  3. On the Site Settings page, Click on "Site Content Types" link under "Web Designer Galleries" section.
  4. On the Site Content Types page, click the name of the content type to be edited.
  5. On the edit page, click the "Name,Description, and Group" link in the Settings section.
  6. On the Content Type Settings page, You can update the Name, Description, and Group information as necessary. 
    sharepoint online update content type powershell
  7. Click OK button to save your changes.

SharePoint Online: Update Content Type using PowerShell
Lets update content type name, description and group 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"

#parameters
$SiteURL="https://crescent.sharepoint.com/sites/projects"
$ContentTypeID="0x01002A7A908ACAB0054880702EE263AC762B"
 
#Get Credentials to connect
$Cred= Get-Credential

Try { 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
     
    #Get content type by ID
    $ContentType = $Ctx.web.ContentTypes.GetById($ContentTypeID)
    $Ctx.Load($ContentType)
    $Ctx.ExecuteQuery()

    #sharepoint online update content type powershell
    If($ContentType -ne $Null)
    {
        #Update Content Type Settigs
        $ContentType.Name = "Crescent Project Proposal V2"
        $ContentType.Description="Project Proposal Content Type with Template V2"
        $ContentType.Group = "Crecent Projects"
        $ContentType.Update($False) 
        $Ctx.ExecuteQuery()

        Write-host -f Green "Content Type Settings Updated Successfully!"
    }
    else
    {
        Write-host "Content Type '$ContentTypeName' doesn't exist!'" -f Yellow
    }
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}
Here is my related posts:
SharePoint Online: Update Content Type using PowerShell SharePoint Online: Update Content Type using PowerShell Reviewed by Salaudeen Rajack on October 14, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.