Created
August 10, 2016 16:21
-
-
Save hombreDelPez/c6239506cee2c63760295e61cd726dfb to your computer and use it in GitHub Desktop.
Sitecore PowerShell script to list all short urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Lists all the short URLs () respectively the set aliases in the system | |
.NOTES | |
Manuel Fischer | |
#> | |
$database = "master" | |
$aliasFolder = "$($database):\sitecore\system\Aliases" | |
$FolderExists = Test-Path -Path $aliasFolder | |
function Get-AllAliases { | |
Get-ChildItem -Path $aliasFolder -Recurse | Where-Object {$_.TemplateName -eq "Alias"} | |
} | |
function Get-PageName ($currentItem) { | |
$field = [Sitecore.Data.Fields.LinkField] $currentItem.Fields["Linked item"] | |
$field.TargetItem.DisplayName | |
} | |
function Get-LongURL ($currentItem) { | |
$field = [Sitecore.Data.Fields.LinkField] $currentItem.Fields["Linked item"] | |
$urlOptions = [Sitecore.Links.UrlOptions]::DefaultOptions | |
$urlOptions.Site = [Sitecore.Sites.SiteContext]::GetSite("website") | |
[Sitecore.Links.LinkManager]::GetItemUrl($field.TargetItem, $urlOptions) | |
} | |
if(!$FolderExists) { | |
Show-Alert "Der Alias-Ordner wurde unter sitecore\system\Aliases nicht gefunden!" | |
} else { | |
$items = Get-AllAliases | |
if($items.Count -eq 0){ | |
Show-Alert "Es wurden keine gesetzten Short-URLs bzw. Aliases gefunden." | |
} else { | |
$props = @{ | |
Title = "Short-URLs - Resultate" | |
InfoTitle = "Gesetzte Short-URLs" | |
InfoDescription = "Zeigt die gesetzten Short-URLS bzw. Aliases an." | |
PageSize = 25 | |
} | |
$items | Show-ListView @props -Property @{Label="Short URL"; Expression={$_.Name} }, | |
@{Label="Page Name"; Expression={Get-PageName -currentItem $_} }, | |
@{Label="Long URL"; Expression={Get-LongURL -currentItem $_} }, | |
@{Label="Item path"; Expression={$_.ItemPath} } | |
} | |
} | |
Close-Window |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For external links , need to be modified by adding
if($field.LinkType -eq "external")
{
$field.Url
}