Office 365 · PowerShell · Project Online · SharePoint

Office 365 – SharePoint – Update list items using PowerShell


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://veenstra.me.uk, SharePains”}

 

 

Advertisements

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

    Like

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

      Like

Please leave a comment or feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s