Administrator, Citrix, Farm, OS, PowerShell, Presentation Server, Script, Server, Utility, Xenapp, Xenapp 5.0, XEnapp 6.5

Powershell script to fetch Citrix Xenapp server sessions information

May 14, 2015

There are different kind of sessions created on Citrix servers. we can get various information regarding sessions either from access management console or Powershell.

In this article I am sharing a script I created to get session information for couple of servers.

The command I user for session information is Get-XAsession. It would give information the sessions with various details.

Below script fetches Sessiontype(ICA, RDP or console), server name and user’s ID.

add-pssnapin Citrix.*
$report = Get-XASession -ServerName Server1 | Select sessionname, servername,accountname
$report += Get-XASession -ServerName Server2 | Select sessionname, servername,accountname

$a = “<style>”
$a = $a + “BODY{font-color:#003399;}”
$a = $a + “TABLE{background-color:#D1E0FF;border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;width:800px;font-color:#003399;}”
$a = $a + “TH{background-color:yellow;border-width: 1px;padding: 0px;border-style: solid;border-color: black;font-color:#003399;}”
$a = $a + “TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;text-align: center;font-color:#003399;}”
$a = $a + “</style>”

$emailFrom = “noreply@virtualsingh.in”
$emailto = “email@virtualsingh.in”
$emailto = $emailto.split(‘,’)
$emailSubject = “Session report for servers Server1 and Server2”
$smtpServer = “smtp Server”

$resultsHTM = “Please find the session report below.”
$resultsHTM = $report | convertto-html -head $a -body “<H2>Session Information</H2><br>” -property SessionName, ServerName, AccountName

$resultsHTM = $resultsHTM | out-string
$mailMessageParameters = @{
From = $emailFrom
To = $emailTo
Subject = $emailSubject
SmtpServer = $smtpServer
Body = $resultsHTM

}

Send-MailMessage @mailMessageParameters -BodyAsHtml

Send-MailMessage @mailMessageParameters -BodyAsHtml

This script will send email with details to email mentioned in $EmailTo variable. You can schedule this script if you want this report at regualar intervals.

In this script the information is fetched for two servers server1 and server2. If you have more servers you can either create array or import them from file. Then a foreach loop can be used to fetch information.

I choose only three properties of session, you can have all or which you like to display.

I hope this would be helpful.

Keep Scripting 🙂

You Might Also Like

No Comments

Leave a Reply