Skip to content

Instantly share code, notes, and snippets.

@SoulOfUniverse
Created July 13, 2021 19:08
Show Gist options
  • Save SoulOfUniverse/1833a1433ad2fa5157ba9377ff668060 to your computer and use it in GitHub Desktop.
Save SoulOfUniverse/1833a1433ad2fa5157ba9377ff668060 to your computer and use it in GitHub Desktop.
Sitecore Powershell Get Item Url Referrer
$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