Tìm kiếm trang web

SharePoint Online: Cập nhật nhiều dòng giá trị trường văn bản bằng PowerShell


Yêu cầu: Cập nhật nhiều dòng giá trị trường văn bản trong SharePoint Online bằng PowerShell.

PowerShell để đặt trường văn bản nhiều dòng trong SharePoint Online:

Tôi có một cột có tên là “Mô tả dự án” thuộc loại “Văn bản thuần túy” trong danh sách “Dự án” và đây là tập lệnh CSOM PowerShell để cập nhật nhiều dòng giá trị trường văn bản trong SharePoint Online.


#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"
 
#Parameters
$SiteURL = "https://Crescent.sharepoint.com/sites/PMO"
$ListName ="Projects"
$FieldName = "Project_x0020_Description"
$ItemID = 1

#Get credentials to connect
$Cred = Get-Credential

Try {
    #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 Item to update
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $ListItem = $List.GetItemById($ItemID)
    $Ctx.Load($ListItem)
    $Ctx.ExecuteQuery()
 
    #Update Multiple lines of text Field value
    $ListItem[$FieldName] = "Project Started: Q1 2018"+[System.Environment]::NewLine+"Completion Goal: Q2 2018"
    $ListItem.Update()
    $Ctx.ExecuteQuery()
    Write-host -f Green "Multiple Lines of Text Field Value has been updated for the list Item!"
    }
Catch {
    write-host -f Red "Error:" $_.Exception.Message    
}

Đây là giao diện của nó trong SharePoint Online:

PnP PowerShell để cập nhật nhiều dòng giá trị cột văn bản

Nếu cột của bạn cho phép Văn bản có định dạng hoặc Văn bản có định dạng nâng cao, Dưới đây là cách cập nhật nhiều dòng giá trị trường văn bản bằng PnP PowerShell:


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sites/PMO"
$ListName = "Projects"
$ItemID = 1
  
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
  
#Update multiple lines of value using PowerShell
Set-PnPListItem -List $ListName -Identity $ItemID -Values @{"Project_x0020_Description"= "<b>Project Started: </b>Q1 2018 <br><b>Completion Goal:</b> Q2 2018"}

Bài viết liên quan