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:

ParameterTypeRequiredDescription
ContentTypeContentTypePipeBindFalseSpecify either the name, ID or an actual content type
IdentityListItemPipeBindTrueThe ID of the listitem, or actual ListItem object
ListListPipeBindTrueThe ID, Title or Url of the list.
ValuesHashtableFalseUse the internal names of the fields when specifying field names
WebWebPipeBindFalseThe 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://sharepains.com, SharePains”}

 

 

By Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

4 thoughts on “Office 365 – SharePoint – Update list items using PowerShell”
  1. 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. 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.