SharePoint Online: ¿Cómo hacer que el campo de lista sea de solo lectura usando PowerShell?
Requisito: Crear un campo de solo lectura en el formulario de lista de SharePoint Online.
¿Cómo configurar un campo de lista como de solo lectura en SharePoint Online usando PowerShell?
¿Está buscando hacer que un campo de lista de SharePoint Online sea de solo lectura? Quizás no haya encontrado ninguna manera de hacerlo a través de la interfaz de usuario, pero me pregunto si PowerShell puede ayudar. En esta publicación de blog, veremos cómo hacer que un campo de lista de SharePoint Online sea de solo lectura usando PowerShell.
#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 to set a Field to Read Only in SharePoint Online List
Function Set-SPOFieldReadOnly($SiteURL, $ListName, $FieldInternalName, [Bool]$IsReadOnly)
{
Try {
#Get Credentials to connect
$Cred= Get-Credential
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the List
$List=$Ctx.Web.Lists.GetByTitle($ListName)
#Get the Field
$Field = $List.Fields.GetByInternalNameOrTitle($FieldInternalName)
$Field.ReadOnlyField = $IsReadOnly
$Field.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "Read Only Settings Update for the Field Successfully!"
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
}
#Set parameter values
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Team Documents"
$FieldInternalName = "Classification" #Internal Name
$IsReadOnly = $True
Set-SPOFieldReadOnly -SiteURL $SiteURL -ListName $ListName -FieldInternalName $FieldInternalName -IsReadOnly $IsReadOnly
Esto configura el campo en solo lectura, ¡incluso en el modo de edición rápida!
PnP PowerShell para establecer un campo de lista en solo lectura
También puede usar PnP PowerShell para hacer que un campo sea de solo lectura en SharePoint Online:
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Team Documents"
$ColumnName = "Classification" #Internal Name
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the Context
$Context = Get-PnPContext
#Get the Field from List
$Field = Get-PnPField -List $ListName -Identity $ColumnName
#Set the Field to Read Only
$Field.ReadOnlyField = $True
$Field.Update()
$Context.ExecuteQuery()
