Replace URL in a SharePoint List

Your ads will be inserted here by

Easy Ads.

Please go to the plugin admin page to set up your ad code.

Had a recent situation where a client had changed the URL of their K2 infrastructure during an upgrade.  Since all the links from their SharePoint lists were now broken it was up for PowerShell to update the 14,000 items. This customer had three lists in the same site with different column names, so I wrote it as a function for re-use.

Your ads will be inserted here by

Easy Ads.

Please go to the plugin admin page to set up your ad code.

function Replace-URL-In-List ([string]$webUrl, [string]$listName, [string]$columnName, [string]$oldValue, [string]$newValue) {
 
    $web = Get-SPWeb $webUrl
    $list = $web.Lists[$listName]
    $allItems = $list.Items
    foreach ($item in $allItems)
    {
         if ($item[$columnName] -like "*"+$oldValue+"*")
         {
            "OLD: " + $item[$columnName] + "    NEW: " + ($item[$columnName] -Replace $oldValue,$newValue)
            $item[$columnName] = ($item[$columnName] -Replace $oldValue,$newValue) #Comment this line out to run as a test
            $item.Update()  #Comment this line out to run as a test
          }
    }
#This is to confirm the values parsed in
"OLD VALUE: " + $oldValue
"NEW VALUE: " + $newValue
 
}
 
$webUrl = "https://portal/web/"
$oldValue = "https://oldK2/_tools"
$newValue = "https://newK2/tools"
 
Replace-URL-In-List -webUrl $webUrl  -listName "Requests" -columnName "ViewForm" -oldValue $oldValue -newValue $newValue

Your ads will be inserted here by

Easy Ads.

Please go to the plugin admin page to set up your ad code.

Leave a Reply

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