Forum Discussion

Eddoria's avatar
Eddoria
Brass Contributor
Mar 24, 2019
Solved

PowerShell Script to find and replace part of url

Good morning, I am new to PS so would appreciate any help.   We have just migrated our SharePoint WSS 3.0 sites to SPO. We have found that in lists which contain a field with URLs, the url in the f...
  • Eddoria 

    Try this Pnponline powershell script and it will replace the word in your existing URL field value

     

    Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/test
    $items =Get-PnPListItem -List testlist
    foreach ($item in $items)
    {
       if($item.FieldValues["URL"].URL-ne $null)
      {
          $Oldvalue = $item.FieldValues["URL"].URL
          $Newvalue = $Oldvalue -replace "sharepoint","sharepoint1/sites"
          Set-PnPListItem -List testlist -Identity $Item.Id -Values @{"URL" = $Newvalue}
       }

Resources