Wednesday, April 20, 2016

SharePoint Online: Delete Content Type using PowerShell

Requirement: SharePoint Online Delete Content Type.

How to delete content type in SharePoint Online?
To delete a content type in SharePoint online, follow these steps:

  • Login to your SharePoint online site >> Click on Site settings gear >> Site Settings 
  • In the Site settings page, Click on "Site Content Types" under 
  • Under Site Content Types page, Click on the name of your content type you wish to delete. 
  • Click on "Delete this site content type " link and confirm the prompt once.
    sharepoint online delete content type using powershell

Delete Content Type using PowerShell in SharePoint Online:
Here is the PowerShell to delete content type in SharePoint Online.
#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 Delete-ContentType()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName

    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 content type from web
        $ContentTypeColl = $Ctx.Web.ContentTypes
        #Check if the content type exists in the site        
        $ContentType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
        If($ContentType -eq $Null)
            Write-host "Content Type '$ContentTypeName' doesn't exists in '$SiteURL'" -f Yellow
            #delete the content type

            Write-host "Content Type '$ContentTypeName' deleted successfully!" -ForegroundColor Green
    Catch {
        write-host -f Red "Error Deleting Content Type!" $_.Exception.Message

#Set parameter values

#Call the function
Delete-ContentType -SiteURL $SiteURL -ContentTypeName $ContentTypeName

Cannot Delete Content Type in SharePoint Online? 
Can't delete the content type? Getting "Another site or list is still using this content type. If you would still like to delete it, please remove the content type from all sites and lists and then try again." Error? Well,  This could be because, you may have lists or libraries associated with the content type you are trying to delete. Here is the solution: SharePoint Online cannot delete content type

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...