Office 365 – SharePoint – Update list items using PowerShell

Office 365 – SharePoint – Update list items using PowerShell

By:

Date:

The PowerShell commands of the PnP Framework have many useful commands that help you manage SharePoint online. One of these commands is the Set-SPOListItem Command.

Set-SPOListItem –Identity <ListItemPipeBind> [–ContentType <ContentTypePipeBind>] [–Values <Hashtable>] [–Web <WebPipeBind>] –List <ListPipeBind>

All the parameters are quite easy to understand:

Parameter Type Required Description
ContentType ContentTypePipeBind False Specify either the name, ID or an actual content type
Identity ListItemPipeBind True The ID of the listitem, or actual ListItem object
List ListPipeBind True The ID, Title or Url of the list.
Values Hashtable False Use the internal names of the fields when specifying field names
Web WebPipeBind False The web to apply the command to. Omit this parameter to use the current web.

The majority of the issues with this command are related to the Values. How do you update all the different column formats. In this article I’m trying to give a full overview of all the possible options.

I have created a list called TestList and I’ve added a list item to the list. For each column type of  I’ve added a new column to the list.

Single line of text columns

Set-SPOListItem -List TestList -Identity 1 -Values @{“Title” = “Title New”}

Multiple lines of text columns

For a simple multiple lines of text column the following will work:

Set-SPOListItem -List TestList -Identity 1 -Values @{“MultiText” = “New text”}

To update formatting in the rich text field use the following syntax by including html.

Set-SPOListItem -List TestList -Identity 1 -Values @{“MultiText” = “<strong>New</strong> text”}

Choice column

For a choice column called Choice that has the options

  • Value 1
  • Value 2
  • Value 3

The following syntax can be used:

Set-SPOListItem -List TestList -Identity 1 -Values @{“Choice” = “Value 1”}

Number column

Set-SPOListItem -List TestList -Identity 1 -Values @{“Number” = “10”}

Currency column

Set-SPOListItem -List TestList -Identity 1 -Values @{“Currency” = “10”}

Date and Time column

Set-SPOListItem -List TestList -Identity 1 -Values @{“DateAndTime” = “03/10/2015 14:16”}

Lookup column

Ok, setting lookups can be really complicated. Well not with the PnP PowerShell commands. Simply use the ID of the item in the Lookup:

Set-SPOListItem -List TestList -Identity 1 -Values @{“Lookup” = “2”}

Yes/No column

Set-SPOListItem -List TestList -Identity 1 -Values @{“YesNo” = “No”}

Person/Group column

Setting a person field is harder

Set-SPOListItem -List TestList -Identity 1 -Values @{“Person” = “3”}

The above sets the person field to the owner group of the site. I found that 1 sets the user to an internal user. 2 gives an invalid user.

Multi-Person column

For a multi-people column the following lines of PowerShell will add 2 people:

$peopleArr = @()

$peopleArr += “ben@mytenant.onmicrosoft.com”
$peopleArr += “chris@mytenant.onmicrosoft.com”
Set-SPOListItem -List “testlist” -Identity 1 -Values @{“People”=$peopleArr}

Hyperlink or Picture column

Set-SPOListItem -List TestList -Identity 1 -Values @{“Hyperlink” = “https://anylink.com, SharePains”}

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There’s a better way — and I can show you exactly what it looks like. I’m the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I’ve been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://staging.sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://staging.sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@staging.sharepains.com

4 responses to “Office 365 – SharePoint – Update list items using PowerShell”

  1. Mathias Avatar
    Mathias

    The description for hyperlink is not working for me, out of:
    Set-PnPListItem -List Project_list -Identity 4 -Values @{“GitURL” = “https://test.com/PRJ007/,GITPRJ007”}

    I get:
    Field: GitURL
    URL: https://test.com/PRJ007/,,GITPRJ007
    Name: https://test.com/PRJ007/,GITPRJ007

    Why?

    1. Pieter Veenstra Avatar

      Hi Mathias,
      Could you try it with a space after the comma and before the title. The url separator is ,space

  2. Dimitar Miriyski Avatar
    Dimitar Miriyski

    Hi Pieter,

    Have you tried obtaining columns of type Person/Group?

    As they are ust pointers to the User Information List, I am having hard time getting those.

    All I get as a return is: Microsoft.SharePoint.Client.FieldUserValue

    1. Dimitar Miriyski Avatar
      Dimitar Miriyski

      Ignore my previous comment, I used .LookupValue e.g. Write-Host “AccountName : ” $listItem[“AccountName”].LookupValue and it’s fine 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.