how to make read only column at content type in SharePoint online

Sunny Rastogi 106 Reputation points
2021-12-21T17:52:03.57+00:00

Hi Team,

Is there any powershell script by which we can make the columns read-only at content type in SharePoint online?

Please let me know if hidden/read-only columns are searchable in SharePoint online?

Looking for your feedback.

Best Regards,
Su

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Echo Du_MSFT 17,316 Reputation points
    2021-12-22T02:52:55.51+00:00

    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!"  
    }  
    

    159434-1.jpg

    159435-2.jpg

    159436-3.jpg

    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!"  
    }  
    

    159448-4.jpg

    159437-5.jpg

    159438-6.jpg

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.