Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active June 20, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/90c6213de7724b61be1d247a3621db81 to your computer and use it in GitHub Desktop.
Save michaellwest/90c6213de7724b61be1d247a3621db81 to your computer and use it in GitHub Desktop.
Add a new Sitecore Desktop shortcut with Sitecore PowerShell Extensions.
class DesktopLink {
[string]$DatabaseName
[string]$Path
[string]$Icon
[string]$Header
[string]$Language
[string]ToString(){
$fields = @()
$fields += [System.Web.HttpUtility]::UrlEncode($this.DatabaseName)
$fields += [System.Web.HttpUtility]::UrlEncode($this.Path.ToString())
$fields += [System.Web.HttpUtility]::UrlEncode($this.Header)
$fields += [System.Web.HttpUtility]::UrlEncode($this.Language)
$fields += [System.Web.HttpUtility]::UrlEncode($this.Icon)
# master^%7b66FD3C09-517C-4691-82AF-E300AC6BA329%7d^MyConcentra en^Office%2f32x32%2fhome.png
return ("{0}^{1}^{2}`t{3}^{4}" -f $fields)
}
}
function New-DesktopShortcut {
param(
[Sitecore.Security.Accounts.User]$User,
[item]$Item
)
$registryKey = "/$($user.Name)/Desktop/Links"
$rawLinks = [Sitecore.Web.UI.HtmlControls.Registry]::GetString($registryKey)
$desktopLinks = $rawLinks.split("|")
$desktopLink = [DesktopLink]::new()
$desktopLink.DatabaseName = $Item.Database.Name
$desktopLink.Path = $Item.ID
$desktopLink.Icon = $Item.Appearance.Icon
$desktopLink.Header = $Item.DisplayName
$desktopLink.Language = $Item.Language.Name
$desktopLinks += $desktopLink.ToString()
#$profileData[$registryKey] = $desktopLinks -join "|"
$rawLinks = $desktopLinks -join "|"
[Sitecore.Web.UI.HtmlControls.Registry]::SetString($registryKey, $rawLinks)
}
function Get-DesktopShortcut {
param(
[Sitecore.Security.Accounts.User]$User
)
$registryKey = "/$($user.Name)/Desktop/Links"
$rawLinks = [Sitecore.Web.UI.HtmlControls.Registry]::GetString($registryKey)
$desktopLinks = $rawLinks.split("|")
$desktopLinks
}
$user = Get-User -Id sitecore\admin
$item = Get-Item -Path "master:" -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
New-DesktopShortcut -User $user -Item $item
Get-DesktopShortcut -User $user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment