i need help with readonly content type on list.

I have sitecollection ex. "sites/SC".

In that sitecollection i have 1000 subwebs ex. "sites/SC/web1".

In each subweb i have one document library ex. "DOCS" (all subwebs are same).

In that library "DOCS" i have content type "Document" and that content type is set to readonly=True (need to be readonly=False).

After that i need to change one field in that list content type from Required=True to Required=False and set that list content type back to Readonly=True.

Need powershell script which:

  1. loop all subwebs
  2. get list by name
  3. get list CT by name
  4. if list CT readonly is set to true, set readonly to false
  5. get CT field by name
  6. if field Required is set to true, change Required to false
  7. change CT back to readonly=true
  8. proceed to next subweb


  • Basically, parent CT on site is set do readonly and propagates changes to all subwebs (create copy from parent and set to readonly) and now when I try from site CT propagate changes (set readonly to false) to all subwebs CT that child copy CT is set to readonly and breaks ;(
    – Marko Tica
    Dec 7, 2018 at 13:58
  • You want someone to write this whole script for you? That's not what this site is for. I suggest you start with step 1 and answer a question if you get stuck on that, and go from there. Dec 10, 2018 at 18:13
  • @DerekGusoff in pnp is get-pnpcontenttype method and that works but I need set-pnpcontenttype to set list contenttype readonly property. That method doesn't exist in pnp.
    – Marko Tica
    Dec 10, 2018 at 20:00

1 Answer 1

    function Set-SPOContentType

param (

$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)

$rootWeb = $ctx.Web  
#$sites  = $rootWeb.Webs 


   # -1- for each subsites in SC
   # foreach($site in $sites) 
   # { 
   # $ctx.Load($site) 
   # $ctx.ExecuteQuery() 
    Write-Host ". Site name: "$rootWeb.Title -f Cyan # Write-Host $site.Title -f Cyan

        Write-Host ".. List name: " $ll.Title
             foreach($cc in $ll.ContentTypes)

                if($cc.Name -eq $ContentTypeName)
                  Write-Host "... CT name: "$cc.Name -f Cyan
                  if($cc.ReadOnly -eq $true)
                  Write-Host  -f Cyan "... ." $cc.Name" CT - ReadOnly is"$cc.ReadOnly" ...setting to False"
                  $cc.ReadOnly =$false

                    foreach($field in $cc.FieldLinks)
                      if($field.Name -eq $CTFieldInternalName)
                        Write-Host  -f Yellow "... .. Field Name:" $field.Name "Required:" $field.Required "...setting to False"
                        $field.Required =$false
                        Write-Host  -f Green "... .. Required:" $field.Required
                  Write-Host  -f Cyan "... setting CT ReadOnly back to True"
                  $cc.ReadOnly =$true
                  Write-Host "___"



        write-host "$($_.Exception.Message)" -foregroundcolor Yellow

# Paths to SDK. Please verify location on your computer.
# Download https://www.microsoft.com/en-us/download/details.aspx?id=42038
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 

# Insert the credentials and the name of the admin site
$AdminPassword=Read-Host -Prompt "Password" -AsSecureString

Set-SPOContentType -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -ListTitle $ListTitle -ContentTypeName $ContentTypeName -CTFieldInternalName $CTFieldInternalName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.