Skip to content

Instantly share code, notes, and snippets.

@fluxdigital
Last active July 6, 2022 15:49
Show Gist options
  • Save fluxdigital/a399d58359c73af89856c12e92182d94 to your computer and use it in GitHub Desktop.
Save fluxdigital/a399d58359c73af89856c12e92182d94 to your computer and use it in GitHub Desktop.
<#
Function used to find the CM Url
#>
function Get-CmUrl($item){
$site = [Sitecore.Sites.SiteContext]::GetSite("website")
New-UsingBlock(New-Object -TypeName "Sitecore.Sites.SiteContextSwitcher" -ArgumentList $site) {
$urlOptions = [Sitecore.Links.LinkManager]::GetDefaultUrlOptions()
$urlOptions.AlwaysIncludeServerUrl = $True
$urlOptions.ShortenUrls = $True
$urlOptions.SiteResolving = $True;
$url = [Sitecore.Links.LinkManager]::GetItemUrl($item, $urlOptions)
return $url.TrimEnd('/')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment