SharePoint Online: PowerShell kullanarak Listeye Birden Çok Satır Metin Sütunu Ekleme
SharePoint Online'daki Çoklu Metin Satırı sütunu, metin değerinin birden çok satırını depolamak için kullanılır. Alan ayarlarına bağlı olarak metin, görseller, HTML biçimli değerler vb. dahil olmak üzere Zengin metin içerebilir. Bu makalede, PowerShell kullanarak SharePoint Online listesine Çoklu Satır Metin sütununun nasıl ekleneceğini tartışacağız.
SharePoint Online'da Listeye Birden Çok Satır Metin Alanı Nasıl Eklenir?
SharePoint Online'daki bir listeye birden çok satırlık metin alanı eklemek için şu adımları izleyin:
- SharePoint Online sitenize göz atın ve Birden çok satırlık metin sütunu eklemek istediğiniz hedef listesine gidin.
- Liste sekmesinin altında şeritteki "Sütun Oluştur" düğmesini tıklayın.
Yeni sütununuza Ad girin, türü "Birden fazla satır metin" olarak belirtin
- Satır sayısı, Metin türü, mevcut metne değişiklik ekleme vb. gibi diğer isteğe bağlı değerleri doldurun ve SharePoint Online listesinde Çok satırlı metin sütunu oluşturmak için "Tamam"ı tıklayın.
PowerShell, SharePoint Çevrimiçi Listesinde Birden Çok Satır Metin Sütunu Oluşturmak İçin
Birden Çok Metin Satırı sütununu eklemek için aşağıdaki PowerShell betiğini kullanabilirsiniz:
#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"
#Custom function to add column to list
Function Add-MultilineTextColumnToList()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ListName,
[Parameter(Mandatory=$true)] [string] $Name,
[Parameter(Mandatory=$true)] [string] $DisplayName,
[Parameter(Mandatory=$false)] [string] $Description=[string]::Empty,
[Parameter(Mandatory=$false)] [string] $IsRequired = "FALSE",
[Parameter(Mandatory=$false)] [string] $IsRichText="FALSE",
[Parameter(Mandatory=$false)] [string] $NumLines = "6",
[Parameter(Mandatory=$false)] [string] $EnhancedRichText = "FALSE"
)
#Generate new GUID for Field ID
$FieldID = New-Guid
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the List
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
#Check if the column exists in list already
$Fields = $List.Fields
$Ctx.Load($Fields)
$Ctx.executeQuery()
$NewField = $Fields | where { ($_.Internalname -eq $Name) -or ($_.Title -eq $DisplayName) }
if($NewField -ne $NULL)
{
Write-host "Column $Name already exists in the List!" -f Yellow
}
else
{
#Define XML for Field Schema
if($EnhancedRichText -eq "TRUE") #Enhanced Rich Text Mode
{
$FieldSchema = "<Field Type='Note' ID='{$FieldID}' DisplayName='$DisplayName' Name='$Name' Description='$Description' Required='$IsRequired' NumLines='$NumLines' RichText='TRUE' RichTextMode='FullHtml' IsolateStyles='TRUE' />"
}
else #Plain Text or Rich Text
{
$FieldSchema = "<Field Type='Note' ID='{$FieldID}' DisplayName='$DisplayName' Name='$Name' Description='$Description' Required='$IsRequired' NumLines='$NumLines' RichText='$IsRichText' />"
}
$NewField = $List.Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)
$Ctx.ExecuteQuery()
Write-host "New Column Added to the List Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Adding Column to List!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$Name="ProjectDescription"
$DisplayName="Project Description"
$Description="Enter the Project Description"
$IsRichText="FALSE" #FALSE for Plain text / TRUE for Rich text
$EnhancedRichText="FALSE" #FALSE for Rich text / TRUE for Enhanced Rich Text, Takes Precedence over IsRichText parameter value
#Call the function to add column to list
Add-MultilineTextColumnToList -SiteURL $SiteURL -ListName $ListName -Name $Name -DisplayName $DisplayName -Description $Description -IsRichText $IsRichText -EnhancedRichText $EnhancedRichText
PnP PowerShell, SharePoint Çevrimiçi Listesine Çok Satırlı Metin Alanı Eklemek İçin
Benzer şekilde, PnP PowerShell betiğiyle Add-PnPField cmdlet'ini kullanın.
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
$ListName= "Projects"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Add Multiple lines of Text Field to list
Add-PnPField -Type Note -List $ListName -DisplayName "Project Description" -InternalName "ProjectDescription" -AddToDefaultView
Bu komut dosyası, "Projeler" listesine "Proje Açıklaması" görünen adı ve "Proje Açıklaması" dahili adı olan yeni bir Çok Satırlı Metin sütunu ekler. XML şemasından SharePoint Çevrimiçi Listesine çok satırlı bir metin alanı da ekleyebilirsiniz.
#Define XML Schema for Multiline Text Field
$FieldXML= "<Field Type='Note' Name='ProjectDescription' ID='$([GUID]::NewGuid())' DisplayName='Project Description' Required ='FALSE' RichText='TRUE' RichTextMode='FullHtml' ></Field>"
#Add Choice Field to list from XML
Add-PnPFieldFromXml -FieldXml $FieldXML -List $ListName
