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 - https://c986.sharepoint.com/sites/dev-int/Lists/Demo/link001.aspx
QA - Link 001 - https://c986.sharepoint.com/sites/dev-qa/Lists/Demo/link001.aspx
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.
- # Input Parameters
- $siteURL="https://c986.sharepoint.com/sites/dev-qa"
- $listName="Links"
-
- # Connect to SharePoint Online site
- Connect-PnPOnline -Url $siteURL -Credentials (Get-Credential)
-
- # Get the list items
- $itemColl=Get-PnPListItem -List $listName
-
- # Loop through each item
- foreach($item in $itemColl)
- {
- # Get the item URL value
- $url=$item["URL"].Url;
-
- # Update the URL
- $updatedURL=New-Object Microsoft.SharePoint.Client.FieldUrlValue
- $updatedURL.Url=$url.Replace("dev-int","dev-qa");
- $updatedURL.Description=$item["URL"].Description;
- $values = @{"URL"=[Microsoft.SharePoint.Client.FieldUrlValue]$updatedURL }
-
- # Get the item Id
- $id=$item.Id
-
- # Update the list item
- Set-PnPListItem -List Links -Identity $id -Values $values
- }
Open PowerShell window and run the following command.
folderlocation –UpdateHyperLink.ps1 file location
Run the following command
Thus in this blog, you saw how to update the hyperlink in the SharePoint Online List Items using PnP PowerShell.