Updated Presence Application

In my last post I created a small powershell script which allowed users to see who was online by using information from the Citrix XenApp data collector.

I wanted to take this a little further to provide other information such as location etc.

The following form is the result.  It has been designed to be used by our support team rather than staff in general.

This shows the user status, the server which they are logged on to, their login time and their relative location.

It also has a Remote Assist button, this will launch remote assistance and show user sessions for that particular server.  Previously our support team had to either ask users which server they were logged on to, or find them in the DSC.  By using the presence form, it will speed up this process and give them other useful information as well.

The location is a tricky subject, to show this I had to add subnet IP addresses into the script.

Below is a copy of the script with some information edited or removed.  As stated in my previous post I am not a powershell guru and I am sure that some elements could be more streamlined.  If you have any comments then feel free to share them!

[system.reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
Function Location
    write-host "launching a function"
$form = New-Object Windows.Forms.Form
$form.text = "Presence"
$label = New-Object Windows.Forms.Label
$label.Location = New-Object Drawing.Point 50,30
$label.Size = New-Object Drawing.Point 200,15
$label.text = "Enter the users name below"
$statuslabel = New-Object Windows.Forms.Label
$statuslabel.Location = New-Object Drawing.Point 35,125
$statuslabel.Size = New-Object Drawing.Point 300,15
$statuslabel.visible = $False
$computerlabel = New-Object Windows.Forms.Label
$computerlabel.Location = New-Object Drawing.Point 35,160
$computerlabel.Size = New-Object Drawing.Point 300,15
$computerlabel.visible = $False
$Logintimelabel = New-Object Windows.Forms.Label
$logintimelabel.Location = New-Object Drawing.Point 35,195
$logintimelabel.Size = New-Object Drawing.Point 300,15
$logintimelabel.visible = $False
$locationlabel = New-Object Windows.Forms.Label
$locationlabel.Location = New-Object Drawing.Point 35,230
$locationlabel.Size = New-Object Drawing.Point 300,15
$locationlabel.visible = $False
$OfferRAbutton = New-Object Windows.Forms.Button
$OfferRAbutton.text = "Remote Assist"
$OfferRAbutton.Location = New-Object Drawing.Point 90,265
$OfferRAbutton.Size = New-Object Drawing.Point 100,30
$OfferRAbutton.visible = $False
$OfferRAbutton.Add_Click({C:\Windows\System32\msra.exe /offerRA $server})
$textfield = New-Object Windows.Forms.TextBox
$textfield.Location = New-Object Drawing.Point 50,60
$textfield.Size = New-Object Drawing.Point 200,30

$button = New-Object Windows.Forms.Button
$button.text = "Go!"
$button.Location = New-Object Drawing.Point 100,90
$locationlabel.visible = $False
$statuslabel.visible = $False
 $computerlabel.visible = $False
    $logintimelabel.visible = $False
if ( (Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null )
{Add-PsSnapin Quest.ActiveRoles.ADManagement}
if ( (Get-PSSnapin -Name Citrix* -ErrorAction SilentlyContinue) -eq $null )
{Add-PsSnapin Citrix*}
$accounts = @(get-qaduser $textfield.text)
$passedname = $textfield.text
If(!$accounts) {$Statuslabel.text = "$passedname cannot be found in the system"
   $statuslabel.visible = $True}
$account = $accounts[0]
$session = Get-XASession -Account $account.ntaccountname -Full | Where {$_.State -ne "Disconnected" -and $_.BrowserName -eq "Desktop"} | sort-object AccountName
$iplocation = $session.ClientIPV4
$fullname = $account.name
$Server = $session.servername
$LoginTime = $session.logonTime
$Statuslabel.text = "$fullname is not logged into My Desktop"
$statuslabel.visible = $True
switch -wildcard ($iplocation)
    "192.168.0.*" {$txtlocation = "Site Ground Floor"}
    "192.168.1.*" {$txtlocation = "Site 1st Floor"}
    "192.168.2.*" {$txtlocation = "Site 2nd Floor"}
    "192.168.3.*" {$txtlocation = "Site 3rd Floor"}
    "192.168.4.*" {$txtlocation = "Site 4th Floor"}
    "172.20.8.*" {$txtlocation = "Site 2"}
    "172.20.9.*" {$txtlocation = "Site 3"}
    default {$txtlocation = "Location cannot be determined"}
$lastinput = $session.LastInputTime
$currenttime =$session.CurrentTime
$idletime =($currenttime - $lastinput).Minutes
if ($idletime -lt 5) {
$Status = "Online"
$Statuslabel.text = "$Fullname is $status"
$computerlabel.text = "Server name = $Server"
$logintimelabel.text = "Login Time = $LoginTime"
$locationlabel.text = "Location = $txtlocation"
    $locationlabel.visible = $True
    $statuslabel.visible = $True
    $computerlabel.visible = $True
    $logintimelabel.visible = $True
    $OfferRAbutton.visible = $True
Elseif ($idletime -gt 4) {
$Status = "Away"
$Statuslabel.text = "$Fullname has been $status for $idletime minutes"
$computerlabel.text = "Server name = $Server"
$logintimelabel.text = "Login Time = $LoginTime"
$locationlabel.text = "Location = $txtlocation"
    $locationlabel.visible = $True
    $statuslabel.visible = $True
    $computerlabel.visible = $True
    $logintimelabel.visible = $True
    $OfferRAbutton.visible = $True
# Add the controls to the Form

# Display the dialog


Popular posts from this blog

Assigning Windows 10/11 Enterprise Subscription Activation Licences to Hybrid Azure AD Joined Devices

Upgrade Samsung Galaxy Ace 2 (I8160) to Android Jelly Bean

Autopilot Hybrid Azure AD Join with Customised First Login Status