0

Using SharePoint 2016

I am trying to update lookup column in a document library via CSV using below PowerShell:

it only updating few and giving below error on rest of the items. The CSV and Doc Library both have 10K+ records.

enter image description here

   Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  
#Read the CSV file
$CSVData = Import-CSV -path "C:\data.csv"
  
#Get the Web
$web = Get-SPWeb -identity "Site collection URL"
  
#Get the Target List
$List = $web.Lists["Library Name"]
  
#Iterate through each Row in the CSV
foreach ($Row in $CSVData)
{
    #Get the List Item matching "EmployeeID" field in the CSV   
    $Item = $List.Items | Where-Object { $_["EmpID"] -eq $Row.EmployeeID }
 
    if($item -ne $null)
    {
        #Update List Item - Internal Name!
        $item["Tecode"] =[int]$row.ID
        #$item.Update()
         $item.SystemUpdate()
        Write-Host "Updated:"$row.EmployeeID -ForegroundColor Green
    }
    else
    {
        write-host "No matching Item Found for:"$row.EmployeeID -f Red
    }
}
1
  • What type of column is 'Tecode'? Commented Jan 17, 2023 at 8:15

1 Answer 1

0

$Item is later used as $item.

Sometimes the "LookupId" is different than the actual user id. Try resolve the user on the web and verify that the ID is correct.

If you resolve the user like this

$spUser = $web.Users.GetByID($row.ID)

You can then use that variables values on "$item["Tecode"]" or double check the LookupId in this list

$web.SiteUserInfoList

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.