How To Update The Hyperlink In The SharePoint Online List Items Using PnP PowerShell

I have created multiple views in different lists (approximately 100) across the site and I am storing those list view URL’s in a link list. I have two different environments, INT and QA. When I migrate the link list from one environment to other environment the link list is migrated with all contents but the URLs have to be updated. For example, see the URL format below for each environment.

INT - Link 001 -

QA - Link 001 -

In order to overcome this, I have written the below PnP PowerShell script which updates the URLs in the link lists.

You can download setup files from the releases section of the PnP PowerShell repository.

Copy the below script and paste it in a notepad. Save the file as UpdateHyperLink.ps1.

  1. # Input Parameters   
  2. $siteURL=""  
  3. $listName="Links"  
  5. Connect to SharePoint Online site  
  6. Connect-PnPOnline -Url $siteURL -Credentials (Get-Credential)  
  8. # Get the list items  
  9. $itemColl=Get-PnPListItem -List $listName  
  11. # Loop through each item  
  12. foreach($item in $itemColl)  
  13. {     
  14.    # Get the item URL value  
  15.    $url=$item["URL"].Url;  
  17.    # Update the URL  
  18.    $updatedURL=New-Object Microsoft.SharePoint.Client.FieldUrlValue   
  19.    $updatedURL.Url=$url.Replace("dev-int","dev-qa");  
  20.    $updatedURL.Description=$item["URL"].Description;  
  21.    $values = @{"URL"=[Microsoft.SharePoint.Client.FieldUrlValue]$updatedURL }  
  23.    # Get the item Id  
  24.    $id=$item.Id     
  26.    # Update the list item  
  27.    Set-PnPListItem -List Links -Identity $id -Values $values  
  28. }  

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"  

folderlocation –UpdateHyperLink.ps1 file location

Run the following command

  1. >.\ UpdateHyperLink.ps1  

Thus in this blog, you saw how to update the hyperlink in the SharePoint Online List Items using PnP PowerShell.