Created
July 13, 2021 19:08
-
-
Save SoulOfUniverse/1833a1433ad2fa5157ba9377ff668060 to your computer and use it in GitHub Desktop.
Sitecore Powershell Get Item Url Referrer
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
$inputProps = @{ | |
Prompt = "Enter the targeted item ID (Guid):" | |
Validation = [Sitecore.Configuration.Settings]::ItemNameValidation | |
ErrorMessage = "'`$Input' is not a valid item ID." | |
} | |
$itemId = Show-Input @inputProps | |
[Sitecore.Context]::SetActiveSite("website") | |
$urlop = [Sitecore.Links.LinkManager]::GetDefaultUrlOptions() | |
$urlop.AddAspxExtension = $false | |
$urlop.AlwaysIncludeServerUrl = $true | |
$urlop.Language = "en" | |
$urlop.LanguageEmbedding = "Always" | |
$urlop.LowercaseUrls = $true | |
$urlop.ShortenUrls = $false | |
$urlop.SiteResolving = $true | |
$referrers = Get-ItemReferrer -Id $itemId | |
$referrers | ForEach-Object { | |
$urlop.Language = $_.Language.Name.ToLower() | |
$url = [Sitecore.Links.LinkManager]::GetItemUrl($_,$urlop) | |
if ($url.IndexOf("/modules/powershell/") -gt 0) { | |
} | |
else { | |
if ($url.IndexOf("http://") = 0){ | |
$url = "http" + $url | |
} | |
$url -replace '[ ]', '-' | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment