How to Update List Items in SharePoint using PowerShell?

Requirement: Update List Items in SharePoint using PowerShell.

Update List Items in SharePoint using PowerShell

How to Update List Items in SharePoint using PowerShell Script?

Updating list items in SharePoint On-premises can be a tedious process, especially if you have to manually do it multiple times a day. You hate doing the same thing over and over again, isn’t it? Well, PowerShell to the rescue! This blog post will show you how to use PowerShell to update list items quickly. Let’s get started!

The basic syntax for updating a list item goes as:

#Get Web and List 
$Web = Get-SPWeb "https://sharepointsite.com"
$List = $Web.Lists["ListName"]

#Get the List item to update
$ListItem = $List.GetItembyID($ItemID)
 
#Set Column values
$ListItem["ColumnName"] = "New Value for the Field!"
 
#Update the Item, so that it gets saved to the list
$ListItem.Update()

Update SharePoint list item using PowerShell script

Let’s take another example:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

$web = Get-SPWeb https://SharePointSite.com

#Get the Contacts List
$List = $web.Lists["Contacts"]

#Get the List Item by its Title field value
$ListItem = $List.Items | Where {$_["Title] -eq "Salaudeen Rajack"}

#Set "Department" column value
$ListItem["Department"] = "IT"

$ListItem.Update() 

Update All List items using PowerShell script:

$web = Get-SPWeb https://SharePointSite.com

#Get the Contacts List
$List = $web.Lists["Contacts"]

#Get All Items by update its title
$ListItems = $List.items
 
#Iterate through each item
foreach($Item in $ListItems)
{
    #Update the value of the "Title" column
    $item["Title"] = "Title Updated!"
 
    #Update the item
    $item.Update()
}

How about Updating Selective List Items in Bulk?

Let’s update a list item by its ID field.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$SiteURL = "https://portal.crescent.com/pipeline/"
$ListName = "Deals"

#Get the List
$List = (Get-SPWeb $SiteURL).Lists.TryGetList($ListName)

#List of Item IDs to update
$ItemIDs = 16,52,69,70,97,170,194,195,196,220,259

If($list)
{
    foreach($ItemID in $ItemIDs)
    {
        #Get Item by ID
        $ListItem = $List.GetItembyID($ItemID) 

        #Update List Item Fields
        $ListItem["Health and SafetyRisk"]="Low"
        $ListItem["Environmental Risk"]="Medium"
        $ListItem["Social Risk"]="High"       

        $ListItem.SystemUpdate()
        Write-host "Updated Item ID:"$ItemID
    }
}

To update list items in SharePoint Online, refer: How to Update SharePoint Online list items using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

5 thoughts on “How to Update List Items in SharePoint using PowerShell?

  • Thanks for this! This has been really useful. Is there a way to check if the update/insert is successful? Does $item.Update return anything?

    Reply
  • $List doesn’t have an Items method?

    Reply
  • Hello
    The command item.update does deletes the values of the column before updating it.
    What if I do only want to update it without deleting before.
    Thank you

    Reply
  • Get-SPWeb : The term ‘Get-SPWeb’ is not recognized as the name of a cmdlet,
    function, script file, or operable program. Check the spelling of the name, or
    if a path was included, verify that the path is correct and try again.
    At line:4 char:1
    + Get-SPWeb https://lon-iwww-dev.swatchgroup.net/Domain/IT/
    + ~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNo
    tFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    And When i try to Add-PSSnapin “Microsoft.SharePoint.PowerShell”

    Add-PSSnapin : The Windows PowerShell snap-in
    ‘Microsoft.SharePoint.PowerShell’ is not installed on this computer.
    At line:1 char:1
    + Add-PSSnapin “Microsoft.SharePoint.PowerShell”
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (Microsoft.SharePoint.PowerShel
    l:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
    dPSSnapinCommand

    Reply
    • You must run this PowerShell from any of the SharePoint Servers of your SharePoint Farm (and not from your desktop!)

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *