On one of my sites, some of the links are to an "external" web site (actually internal but not part of, or a subsite of, this one). I need to change all of those, but I can't see any way to find them that's better than manually going through every single page, and every link on every page.

This question may be a duplicate of: Get All Hyperlinks in web application

However, that question was never answered, so ....


1 Answer 1


Source: Find and Replace URL Links from Hyperlink Columns in SharePoint

You can use the below PowerShell code :

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue


Function Replace-LinkFields($WebURL, $OldLinkURL, $OldLinkTitle, $NewLinkURL, $NewLinkTitle)


    #Get the Web

    $Web = Get-SPWeb $WebURL


    #Get all lists - Exclude System lists

    $ListCollection = $web.lists | Where-Object  { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false) -and ($_.Author.LoginName -ne "SHAREPOINT\system") }


    #Iterate through each list

    foreach ($List in $ListCollection)


        #find all HyperLink fields in list

        $HyperlinkFields = @()

        foreach ($field in $list.Fields)


            if ($field.TypeAsString -eq "URL")


                $HyperlinkFields = $HyperlinkFields + $field.Title     



        write-host "Processing list at: $($web.url)/$($list.RootFolder.Url)"


        #Process all hyperlink fields found


        #Proceed with next list if Hyperlink field is not found in the list

        if($HyperlinkFields.Count -eq 0) { continue }


        foreach ($Item in $List.Items)


            #Iterate through HyperLink fields

            foreach ($field in $HyperlinkFields)


                #Get field value

                $FieldValue = $item[$field]

                #Skip nulls

                if($FieldValue -ne $null)


                    # Check for OldLinkURL or OldLinkTitle

                    if( ($FieldValue.contains($OldLinkURL)) -or ($FieldValue.contains($OldLinkTitle)) )


                        #Replace the OLD URL with New URL

                        $Item[$field] = ($item[$field] -Replace $OldLinkURL,$NewLinkURL)

                        #Replace OLD link title with new link title

                        $Item[$field] = ($item[$field] -Replace $OldLinkTitle,$NewLinkTitle)



                        Write-host "Found and replaced a old link item at: $($web.Url)/$($list.RootFolder.Url) - Item id: $($item.id)"     








Call the function to Replace Links in lists

Replace-LinkFields "http://Intranet.crescent.com/" "http://portal.crescent.com"  "Crescent Intranet"


  • The above code replacing the old link to a new link, so if you just want to get details of links then you can comment on the link update code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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