I am working with SP On Prem 2019. In one of the document libraries, I have about 440 files which has a metadata field of type 'hyperlink' called 'Main Letter'. This hyperlink field contains link to a document in same library.

Out of 440 Files, there are about 8-9 hyperlinks used for tagging as metadata, sample display text of these hyperlinks are as below:

  1. Document Revised Update 8
  2. LCA Updated
  3. Initial Proposal I

So maybe using PowerShell, I want to grab the rows where 'Main Letter' display text is 'LCA Updated' and update the URL to what I supply in like www.google.com and the same I can do for the remaining 7-8 hyperlink display texts as well.

Can someone please help me with script or flow that I can run, thanks in advance.

1 Answer 1


Use the below script to Update the Hyperlink field. Hope this may help you!

$ListName = "<Document Library>"
$FieldName = "URL"

$hyperLinkDisplayText = "Support Center"
$hyperLinkOldURL = "/sites/support" #Here you provide the old url which you want to search
$hyperLinkNewURL = "/sites/supportV2"  #Here you provide the New url which you want to Replace

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$List = $Ctx.Web.lists.GetByTitle($ListName)

#Define the CAML Query to Filter by Hyperlink value and Get List Item
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "@
            <Eq >
                <FieldRef Name='$FieldName' /><Value Type='URL'>$hyperLinkOldURL</Value>
            </Contains >

$ListItems = $List.GetItems($Query)

If($ListItems.Count -gt 0)
    ForEach($Item in $ListItems)
        $HyperLinkField = [Microsoft.SharePoint.Client.FieldUrlValue]$Item[$FieldName]
        $HyperLinkField.Url = $hyperLinkNewURL
        $HyperLinkField.Description = $HyperlinkDescription

        #Update Hyperlink Field
        $Item[$FieldName] = $HyperLinkField

        Write-host "Hyperlink Field Value Updated in Link List!" -ForegroundColor Green
    Write-host "Hyperlink Field Value '$($hyperLinkOldURL)' Not Found in Link List!" -ForegroundColor Yellow
  • Thanks a lot Krunal, appreciate it. I ran the script and it worked well. However it also updated the display text of the hyperlink field to the new url, is there a way to not update display text ?
    – mdevm
    Sep 25, 2019 at 18:13
  • Any thoughts, Krunal?
    – mdevm
    Sep 26, 2019 at 12:56
  • As you know the display text, you can add the same text in the description field Sep 27, 2019 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.