0

We have a document library with around 1000 documents, most of the documents have links to different locations in our SharePoint, is there anyway I can get a report of how many of these links are broken?

1 Answer 1

0

You can run a powershell script to return all the links in your library then test those links. If you know that the links are supposed to point to items in document libraries, inventory you can test the links to see if they point to a valid link (you can import "output_file" to Excel to read it)

Here is some code to inventory the .url files:

$link_arr = @() # the list of links we found in url files


#Get all the items in this library
$Items = (Get-PnPListItem -List $list_name  -PageSize 2500).FieldValues    

foreach($Item in $Items)
{
  if ($Item.File_x0020_Type -eq "url" ){

    $Regex = [Regex]::new("(?<=URL=)(.*)(\?)")           
    $Match = $Regex.Match($text)

    # remove the query parameters (this could be done via RegEx above)
    $link_url = ($Match.Value).Replace("?","")
    $link_url = [System.Web.HttpUtility]::UrlEncode($link_url)

    $link_arr += [PSCustomObject] @{
      'ID' = $Item.ID
      'List' = $list_name
      'CurrentLink'  = $link_url
    }  
  } 
$link_arr | ConvertTo-CSV -NoTypeInformation -Delimiter "`t" | ForEach-Object {$_ -replace '"', ""} | Set-Content -Path "out_file" -Force
1
  • This requires that you install PNP.Powershell and login in to your SharePoint site before you run the script Apr 11, 2022 at 15:43

Your Answer

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

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