locked
PowerShell CSOM Update with CSV Column RRS feed

  • Question

  • Want to update a list field value using CSOM PowerShell.

    The value is coming from a CSV File Column.

    Could you give me an example ?

    Monday, June 1, 2020 11:26 AM

Answers

  • Hi developer sp,

    You will need to specify another ID column and fill with Item Id value in CSV:

    And use the PowerShell script below to update List field:

    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"
    
    
    
    $SiteUrl = "https://Tenant.sharepoint.com/"
     
    $UserName="user@Tenant.onmicrosoft.com"
    $Password ="******"
      
    #Setup Credentials to connect
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
      
    #Set up the context
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $Context.Credentials = $credentials
    $Context.ExecuteQuery()
    $listsColl=$Context.Web.Lists
    $Context.Load($listsColl)
    $Context.ExecuteQuery()
    $list=$listsColl.GetByTitle("JqueryList")
    $Context.Load($list)
    $Context.ExecuteQuery()
    
    $Data = Import-CSV -path C:\Users\JsIBM\Desktop\Test.csv
    
    foreach ($row in $Data) 
    {
      $ListItem=$list.GetItemById($row.ID)
      $ListItem["Title"]=$row.Title
      $ListItem.Update()
      
    }
    $Context.ExecuteQuery()

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, June 2, 2020 2:54 AM