Hello @Sunny Rastogi ,
Welcome to Q&A Forum!
PnP PowerShell to Make a Content Type Read Only:
Note:
The Content Type is read-only at the entire SharePoint site level
#Config Variables
$SiteURL = "https://domain.sharepoint.com/sites/sitename"
$ContentTypeName ="xxxx"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the Client Context
$Context = Get-PnPContext
#Get the content type from site
$ContentType = Get-PnPContentType -Identity $ContentTypeName
If($ContentType)
{
#Set the Content type to Read Only
$ContentType.ReadOnly = $True
$ContentType.Update($False) #Update children
$Context.ExecuteQuery()
Write-host -f Green "Content Type '$ContentTypeName' is Set to Read Only!"
}
Set the content type to read-only at list level:
#Config Variables
$SiteURL = "https://domain.sharepoint.com/sites/sitename"
$ContentTypeName ="xxxx"
$ListName ="yyyy"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the Client Context
$Context = Get-PnPContext
#Get the content type from List
$ContentType = Get-PnPContentType -Identity $ContentTypeName -List $ListName
If($ContentType)
{
#Set the Content type to Read Only
$ContentType.ReadOnly = $True
$ContentType.Update($False) #Update children
$Context.ExecuteQuery()
Write-host -f Green "Content Type '$ContentTypeName' is Set to Read Only!"
}
Thanks,
Echo Du
==========================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.