SharePoint Online: Update Multiple Lines of Text Field Value using PowerShell

Requirement: Update Multiple lines of text field value in SharePoint Online using PowerShell.

PowerShell to Set Multiline text field in SharePoint Online:

I have a column called “Project Description” of “Plain text” type in the “Projects” list, and here is the CSOM PowerShell script to update multiple lines of text field value in 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    
}

Here is what it looks like in SharePoint Online:

Update Multiple Lines Of Text Field Value in SharePoint Online using PowerShell

PnP PowerShell to Update Multiple Lines of Text Column Value

If your column allows Rich text or Enhanced rich text, Here is how to update multi-lines of text field value with 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"}

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

3 thoughts on “SharePoint Online: Update Multiple Lines of Text Field Value using PowerShell

  • I’d like to create links to another list items in a rich text column (the reason for this is that the list I link to is containing more than 5000 items which makes it impossible to link to directly)
    with the below code I’m ending up with a system.object instead of links.

    ForEach ($system in $SystemListItem)
    {
    Write-Host “now processing System: $($System[“Title”])”
    $computers = ($ListItemCollection | Where-Object { $_.”System Name” -eq $($System[“Title”])})
    $LookupValueCollection = @()
    $LookupValueCollection += ”
    foreach ($computer in $computers)
    {
    $LookupValueCollection += @”
    $($computer.ComputerName)
    “@
    }

    $LookupValueCollection += @”

    “@
    $system[“Related_x0020_Computers”] = $LookupValueCollection
    $system.Update()
    $Ctx.ExecuteQuery()
    Write-host -f Green “Multiple Lines of Text Field Value has been updated for the list Item!”
    }

    Reply
    • Hi Martin,

      Just change the line “$system[“Related_x0020_Computers”] = $LookupValueCollection” to : $system[“Related_x0020_Computers”]” = [system.String]::Join(“”, $LookupValueCollection)

      This will convert the Array into a string.

      Reply
  • Hi
    How do we show the vaules of Project Description at once? SharePoint only shows 6 lines?
    I’d to show large string to a field, but SharePoint won’t show all the string at once.
    Thanks

    Reply

Leave a Reply

Your email address will not be published.