Thursday, January 11, 2018

Sitecore Powershell :: Redirect URL List


I wanted to make my hand dirty by exploring more on Sitecore Powershell, So I installed “Sitecore PowerShell Extensions-4.7 for Sitecore 8” Package and started looking into the ISE and console with existing Scripts. Suddenly something came to my mind. And, its the idea to list the Redirect URL in our site (Which may be huge in other sites).

Perquisites:   Redirect Module should have been used on your site.
Process:
Firstly, I created a new Redirect Powershell Script Module under Script Library.
And then, I created a Toolbox Script Library and then Redirect URL List Script.


In Scripting field, I wrote the below scripts:
# Get all the items recursively where the TemplateName equals "Redirect Url".
Get-ChildItem -Path master:\sitecore\system\Modules -Recurse | 
Where-Object { $_.TemplateName -match "Redirect Url"  } |
    Show-ListView -Property @{Label="Name"; Expression={ $_.DisplayName } },
  @{Label="Requested Url"; Expression={ $_.Fields["Requested Url"]} },
  @{Label="Response Status Code"; 
Expression={ $_.Database.GetItem($_.Fields["Response Status Code"]).Name} },
  @{Label="Redirect To Item"; 
Expression={ [Sitecore.Links.LinkManager]::GetItemUrl($_.Database.GetItem($_.Fields["Redirect To Item"]))} },
  @{Label="Redirect To Url"; Expression={ $_.Fields["Redirect To Url"]} }  `
        -Title "Redirect URL List"
        
Close-Window


After the completion of the Creation process, It should be listed in Powershell Toolbox as below.


Below is the result obtained on the click of Script created,:


Explanation:
This will extract all the items with the template name “Redirect URL”. In the List view property, the fields have been bound. To get the Redirect Item, I used Linkmanager that gives the Item URL.

Download the Sitecore Package: Redirect URL list Package

No comments:

Post a Comment