PowerShell script to update SharePoint list or library Columns based on file name in the CSV File.
Sharepoint Site
Update SharePoint List/Library Column With Matching Input
Input File
Name ECMSourcePath
Abc.doc /SiteCollection/SubSite/Library/Raghav
File1.pdf /SiteCollection/SubSite/Library/Sai
File4.pdf /SiteCollection/SubSite2/Library/Test
Script
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  2. $Site= Get-SPSite "http://sharepoint2019/sites/RaghavSite"
  3. $CSV_Input = Import-Csv "C:\Raghav\Input.csv"
  4. $ItemSuccess = @()
  5. #Iterating the Site Collection
  6. foreach($Web in $Site.AllWebs)
  7. {
  8. #Iterating the Site Objects
  9. foreach($List in $Web.Lists)
  10. {
  11. #Condition to check only the document libraries and skipping the default libraries which created while sitecollections gets created.
  12. if(($List.BaseType -eq "DocumentLibrary") -and ($List.Title -ne "Pages") -and ($List.Title -ne "Web Part Gallery")
  13. -and ($List.Title -ne "Theme Gallery") -and ($List.Title -ne "Site Pages") -and ($List.Title -ne "Converted Forms")
  14. -and ($List.Title -ne "Master Page Gallery") -and ($List.Title -ne "SiteAssets")
  15. -and ($List.Title -ne "PublishingImages") -and ($List.Title -ne "SiteCollectionDocuments")
  16. -and ($List.Title -ne "Style Library") -and ($List.Title -ne "FormServerTemplates"))
  17. {
  18. #Iterating the Input csv file
  19. foreach ($Value in $CSV_Input)
  20. {
  21. #Fetching the List Item Title Field "Name" field in the CSV whereas internal Name is Title. change accordingly as per your field name
  22. $Item = $List.Items | Where-Object { $_['Name'] -eq $Value.Name }
  23. if($Item -ne $null)
  24. {
  25. #Setting ECMSourcePath Field Value from input file .
  26. $Item["ECMSourcePath"] = $Value.ECMSourcePath
  27. $ECMFolderUpdate=$Value.ECMSourcePath
  28. #ECMFolder Value is the last value before the '/' delimiter for extracting we use string functions.
  29. $ECMFolderUpdate=$ECMFolderUpdate.Substring($ECMFolderUpdate.lastIndexOf('/')).Replace('/' ,'')
  30. $Item["ECMFolder"] = $ECMFolderUpdate
  31. #To Avoid the Timestamp Values of Modified and Modified By here we using Item.SystemUpdate($false) you can also use Item.Update as well.
  32. $item.SystemUpdate($false)
  33. #Exporting the Update details to Output File.
  34. $itemdetail = New-Object System.Object
  35. $itemdetail | Add-Member -MemberType NoteProperty -Name "ListName" -Value $Item.ParentList
  36. $itemdetail | Add-Member -MemberType NoteProperty -Name "ItemName" -Value $Item.Name
  37. $itemdetail | Add-Member -MemberType NoteProperty -Name "ItemUrl" -Value $Item.Url
  38. $ItemSuccess +=$itemdetail
  39. Write-Host "Updated in the Site: " $web.Url "- library :" $List.Title "Item:" $Item.Name -ForegroundColor DarkCyan
  40. }
  41. }
  42. }
  43. }
  44. }
  45. $ItemSuccess | Export-CSV -Path "C:\Raghav\SuccessFile.csv" -NoTypeInformation -Force
  46. Write-Host "Script Completed" -foreground Green
Script Output
Update SharePoint List/Library Column With Matching Input
Update SharePoint List/Library Column With Matching Input