I am working on an enterprise wiki site collection and I have two libraries; “Page” which contain the html wiki pages & “Documents” which contain uploaded documents. Now on some wiki pages users upload documents inside the “Documents” library (such as word document or pdfs), and then they reference them inside the wiki pages.

So my question is that we need to identify all the wiki pages that have links to documents , so is this possible?. Now for a wiki pages if I want to know all the wiki pages that are referencing it, I can check the “incoming links” option under “Page Option” tab,, so is there a similar option for the documents? i mean to check which wiki pages are referencing it ?


1 Answer 1


The SPFile object has a ForwardLinks and BackwardsLink property that contain SPLinkCollection that you may be able to query.

Add-PSSnapin Microsoft.SharePoint.Powershell -ea 0;

$web = get-spweb '<url>'
$list = $web.lists['Pages'];

foreach($file in $list.items){
    $links = $file.ForwardLinks;

    foreach($link in $links){
        if($link.url -like '*/Documents/*'){
            Write-Host $file.name $link.url


You can also use CSOM - which doesn't appear to expose the ForwardLinks/BackwardLinks properties, but I was able to get at the HTML content of the page and could search across that as a string.


$weburl = 'https://<URL>';
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl) 

$ctx.Credentials = Get-Credential;

$web = $ctx.Web;

$list = $web.Lists.GetByTitle('Pages');

#Note - you can create a specific CAML query to get specific documents as well.
$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(10);
$items = $list.GetItems($query);


foreach($fileItem in $items){
    $pageContent = $fileItem['PublishingPageContent'];
    If($pageContent | select-string -Pattern '/documents/' -SimpleMatch){
        #page has link to documents library
        Write-Host "Page has link"

  • thanks for the reply, i tried your script but i got the following exception on the "PS H:\> $ctx.ExecuteQuery();" command :- Exception calling "ExecuteQuery" with "0" argument(s): "List 'Pages' does not exist at site with URL 'tvstg01/kb/customerservicekb'." At line:1 char:1 + $ctx.ExecuteQuery(); + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ServerException
    – John John
    May 19, 2015 at 21:54
  • i used exactly the same script you provide but i changed the "$weburl = 'https://<URL>';" to match mu site collection URL.
    – John John
    May 19, 2015 at 21:56
  • any idean what is the problem ?
    – John John
    May 20, 2015 at 9:57
  • It can't find your library in that site. Is that URL your website where the list exists or if that list itself? I may have some time this afternoon to try the alternative approach from the server. May 20, 2015 at 12:13
  • 1
    If you have access to the server the code I added in the update may be easier for you to use. May 20, 2015 at 17:46

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.