Powershell LinkManager UseDisplayName property not working

Hi all, 

I am working on a Sitemap generator in Powershell for multilingual sites and I am having an issue with the LinkManager.

I changed some of the url options and they all seem to work except UseDisplayName. 

 

When I put a breakpoint and mouse over url options, it shows that UseDisplayName is set to true, but if I use the Immediate Window and get the value, it is returned as false.

Regardless, the display name is never used.

 

Here is a code sample:

$urlOptions = [Sitecore.Links.LinkManager]::GetDefaultUrlOptions()

$urlOptions.UseDisplayName -value $True
$urlOptions.AlwaysIncludeServerUrl = $True
$urlOptions.ShortenUrls = $True
$urlOptions.SiteResolving = $True
$urlOptions.Language = "fr-ca"

$myUrl = [Sitecore.Links.LinkManager]::GetItemUrl($myItem, $urlOptions)

Any idea what I could be doing wrong?

Thanks!

Marc

  • Try adding $urlOptions.Site
    $urlOptions.Site = [Sitecore.Sites.SiteContext]::GetSite("SiteNameGoesHere")

    if ($pageLinkedItem.Language -eq "fr-ca") {
    #Get-ItemURL
    $urlOptions = [Sitecore.Links.UrlOptions]::DefaultOptions
    $urlOptions.Site = [Sitecore.Sites.SiteContext]::GetSite("SiteNameGoesHere")
    $pageItemURL = [Sitecore.Links.LinkManager]::GetItemUrl($pageLinkedItem, $urlOptions)
    $fullPageURL = $pageItemURL.Replace('://mysite.com/fr','https://mysite.com/fr')
    }

    Thank you

    Nagendra Ponnaganti