SharePoint Online: PowerShell Kullanarak Liste Alanını Salt Okunur Hale Getirme?
Gereksinim: SharePoint Çevrimiçi Liste formunda bir Alanı Salt Okunur hale getirin.
PowerShell kullanarak SharePoint Online'da Liste Alanını Salt Okunur Olarak Nasıl Ayarlayabilirim?
SharePoint Online liste alanını salt okunur hale getirmek mi istiyorsunuz? Belki bunu kullanıcı arayüzü aracılığıyla yapmanın bir yolunu bulamadınız, ancak PowerShell'in yardımcı olup olamayacağını merak ediyorum. Bu blog yazısında, PowerShell kullanarak SharePoint Online liste alanının nasıl salt okunur hale getirileceğine bakacağız.
#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
Bu, Hızlı Düzenleme modunda bile alanı salt okunur olarak ayarlar!
PnP PowerShell Liste Alanını Salt Okunacak Şekilde Ayarlamak İçin
SharePoint Online'da salt okunur bir alan oluşturmak için PnP PowerShell'i de kullanabilirsiniz:
#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()
