0

I would like to take a list of external links (http:// or https://) referenced in our website from our Sitecore content tree.

I need to compare with all Sitecore Fields(Rich text, general link, single link text, multiline text, etc) and take the list.

Is there any Powershell script to get the list?

2
  • You mean you need to loop through each item in the content tree and then need to check for the fields you mentioned and see if they are having any HTTP or HTTPS links contained right? Commented Jun 22, 2022 at 5:28
  • A similar question was answered previously. Have a look sitecore.stackexchange.com/questions/2572/…
    – rvsure
    Commented Jun 24, 2022 at 7:16

2 Answers 2

3

You can use below PowerShell script for text search

$startPath = "web:/sitecore/content/home"
Write-Host "Search started $(Get-Date -format 'u')"

$linkProvider = [LM.Lightcore.Links.LinkProvider]::new()

$urlOptions = [Sitecore.Links.UrlOptions]::new();


$list = @()
$itemsToProcess = Get-ChildItem $startPath -Language * -Recurse
if($itemsToProcess -ne $null) {
    $itemsToProcess | ForEach-Object { 
        $match = 0;
        foreach($field in $_.Fields) {
                if($field -match '.*http://*') {
                     $item = Get-Item ("web:" + $_.ID)
                    $info = [pscustomobject]@{
                        "FullPath"=$_.Paths.FullPath
                        "ItemUrl"=$linkProvider.GetItemUrl($item, $urlOptions)
                      
                       
                    }
                    $list = $list+$info
                  
            }
        }
    }
}
Write-Host "Search ended $(Get-Date -format 'u')"
Write-Host "Items found: $($list.Count)"

$list | Show-ListView -Property @{Label="FullPath"; Expression={$_.FullPath} },
                                @{Label="ItemUrl"; Expression={$_.ItemUrl} }

Please try it, it will provide you list of items with item URL.

2

You can use this simple approach to start with your code. It will loop through all the items in the content tree with the start node you have given and check for a particular template item.

Then for each item it will search for fields and match the value that you want and will produce the values in the output and if you want you can list the Item or fields in the output as well.

Here is the code.

# Get all the child items under Home item where template name is test
$items = Get-ChildItem -Path master:/Sitecore/content/Home -Recurse | Where-Object { $_.TemplateName -eq "test"}

# Loop on each item that you get above
foreach($item in $items) 
{
    # Loop for each item field 
    foreach($field in $item.Fields) 
    {
        # Check the value in the field that you want to search. In this case we are searching for HTTP and HTTPS
        if($field -match '.*http.*') 
        {
            # Show the Items those fields are having the values that you want
            Write-Host $item.Name
        }
    }
}

It will give you the list of items in output like this.

enter image description here

Hope this is good for the starting point.

For more advanced information, please refer to this blog.

https://www.logicalfeed.com/posts/1222/powershell-script-to-search-a-keyword-in-all-items-in-sitecore

Thanks

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.