For my day job, I wanted know the name of the ‘Citrix’ desktop on which I was currently logged in, because some features are only available on certain desktops in our environment.
So, depending on the desktop, my Powershell profile should (or should not) do particular things (like attempting to import specific modules, etc.).
My brief research on that topic didn’t lead me to a definitive answer, but a hint from a colleague from the Terminal Server team was a big help. That’s why I look into the registry to find out where I am.
Note that I didn’t spend much time investigating any ‘Citrix’-specific cmdlets, because I don’t have access to these modules and cmdlets anyway in my use case; and from what I’ve read so far, they don’t seem to be very helpful for this task.
There’s only one thing in my current solution that I’m not so sure about yet:
Although I’ve only ever found exactly one key under “Session” where my username appears in the first couple of days of my usage,
I don’t know enough about Citrix to be certain whether this is just temporary luck, or if one one day, additional entries may appear there
(for example under ...\Session\1\Connection
and ...\Session\9\Connection
and ...\Session\22\Connection
).
If that happens, maybe additional filtering (for the UserLogonTime) may help.
But I’ll worry about that when (if) it is necessary.
$UserID = ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name -split '\\')[1]
try
{
$PN = Get-ChildItem "HKLM:\SOFTWARE\Citrix\Ica\Session\[0-9]*\Connection" -EA Stop | % {
if ((Get-Item "HKLM:$_").Property -contains 'UserName')
{
Get-ItemProperty "HKLM:$_" | ? { $_.UserName -eq $UserID } | select -expand PublishedName
}
}
switch -wildcard ($PN)
{
"Foo*" { $Desktop = "Foo" }
"Bar*" { $Desktop = "Bar"}
default { $Desktop = "Unknown" }
}
}
catch [System.Management.Automation.ItemNotFoundException]
{
write-host $_.Exception.Message -ForegroundColor Red
$Desktop = $null
}
"Desktop: '$Desktop'"
Film & Television (54)
How To (63)
Journal (17)
Miscellaneous (4)
News & Announcements (21)
On Software (12)
Projects (26)