DEV Community

Tony Watters
Tony Watters

Posted on

1 1

How to make SharePoint column fields readOnly / Hidden with PnP PowerShell


Param(
    $tenantUrl = "https://YOURSITE.sharepoint.com",
    $spCredential = (Get-Credential),
)

$sites = @("siteOne", "SiteTwo")

foreach($name in $sites) {

    Connect-PnPOnline -Url $tenantUrl/sites/$name -Credentials $spCredential

    #Field Guids

    $Summary = Get-PnPField -Identity 98e1ecf3-3ae3-44a4-820c-f1de12ff346a
    $Country = Get-PnPField -Identity 7d9fd33a-e726-4d7f-b3ed-60e1c8e9690d
    $Location = Get-PnPField -Identity 0d2db348-a438-48f2-bcd2-461acd6f149f
    $Language = Get-PnPField -Identity 81b712c3-a41f-4e65-9a3a-8e7110bd9b5e
    $Topic = Get-PnPField -Identity 5f9fd169-0cf6-4779-a6be-e4635327c9a8

    $columns = $Summary, 
               $Country,
               $Location, 
               $Language, 
               $Topic


    foreach ($column in $columns) {

        try{
            $column.ReadOnlyField = $true
            $Column.SetShowInEditForm($false)
            $column.UpdateAndPushChanges($true)
            $column.Context.ExecuteQuery();
        }
        catch{
            Write-Host "error" $columns
        }
    }
    Write-Host "finished updating read Only fields in" $name
}


Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay