• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
ControlUp Community

ControlUp Community

Connect, Learn, and Grow

  • Blog
  • Archives
  • Findings
  • Meetups
  • Videos
  • Events
  • Categories
    • ControlUp One Platform
    • ControlUp for Apps
    • ControlUp for Compliance
    • ControlUp Dashboards
    • ControlUp for Desktops
    • ControlUp for VDI
    • ControlUp Scripts & Triggers
    • ControlUp Synthetic Monitoring
    • ControlUp Workflows
  • Topics
    • Logos & Wallpaper
    • ControlUp.com
  • Join

Script for Monitoring Published App and Desktop Session Statistics with ControlUp

Posted on December 2, 2022

A user shared a script for a furniture company that was designed to show the number of sessions for published apps and desktops, and the percentage of the total for each of them. The script must be run on the ControlUp Monitor version 8.6.5 or newer and it was modified to allow for large amounts of sessions. The results use Export-CUQuery instead of Invoke-CUQuery. The discussion also included tips regarding color scheme and location.


Read the entire ‘Script for Published App and Desktop Session Statistics with ControlUp’ thread below:

I thought it would be nice to share a script I wrote for a furniture company up north. THey wanted to see how many sessions there were for each published app and published desktop. And also how many % of the total # of sessions for each of these. This is the script. Needs to run on the ControlUp monitor. You require version 8.6.5 for this.


“`$pathtomodule = (Get-ChildItem "C:\Program Files\Smart-X\ControlUpMonitor*ControlUp.PowerShell.User.dll" -Recurse | Sort-Object LastWriteTime -Descending)[0]

Import-Module $pathtomodule

Fields to get from Invoke-CUQuery xdApplicationsInUse, xdDeliveryGroup

For a full list of fields to fetch, run this command: (Invoke-CUQuery -Table Sessions -Fields *).Data | gm -MemberType NoteProperty

Fetch all Citrix sessions

$reportdownload = Export-CUQuery -Scheme Main -Table Sessions -Fields sUserName, xdApplicationsInUse, xdDeliveryGroup, sApplication -where "xdProtocol = ‘HDX’"

$sessions = import-csv ($reportdownload.FullFilePath) #import the data generated by the Export-CUquery cmdlet

Get-ChildItem ($reportdownload.FullFilePath) | Remove-Item -force #remove the csv from the Export-CUquery cmdlet

Only select sessions which have a published app in use

$pa = $sessions | where {$_.xdApplicationsInUse.Length -gt 1}

$response = @{}

Count how many sessions each published app has

foreach ($session in $pa)

{

foreach ($publishedApp in $session.xdApplicationsInUse.Split([Environment]::NewLine)){

if ($publishedApp -ne "" -and $response.ContainsKey($publishedApp))

{

$count = $response[$publishedApp]

$count++

$response[$publishedApp] = $count

}

else

{

if ($publishedApp -ne "") {$response.Add($publishedApp, 1)}

}

}

}

Fill the totals table

foreach ($item in $response.Keys)

{

$row = $totals.NewRow()

$row.Service = $item

$row.Sessions = $response[$item]

$row.’%of Total Sessions’ = [Math]::Round(($response[$item]/$sessions.Count * 100),2)

$totals.Rows.Add($row)

}

Send feedback to SBA window

Write-Output "Published application statistics"

Write-Output $totals | Format-Table

Get published applications

$PDsessions = $sessions | where {$_.sApplication.Contains("$")}

$responsePD = @{}

Count how many sessions each published desktop has

foreach ($session in $PDsessions)

{

$PDName = $($session.sApplication.Split("$"))[0].Trim()

if ($PDName -ne "" -and $responsePD.ContainsKey($PDName))

{

$count = $responsePD[$PDName]

$count++

$responsePD[$PDName] = $count

}

else

{

if ($PDName -ne "") {$responsePD.Add($PDName, 1)}

}

}

foreach ($item in $responsePD.Keys)

{

$row = $totalsPD.NewRow()

$row.’Published Desktop’ = $item

$row.Sessions = $responsePD[$item]

$row.’%of Total Sessions’ = [Math]::Round(($responsePD[$item]/$sessions.Count * 100),2)

$totalsPD.Rows.Add($row)

}

Send feedback to SBA window

Write-Output "Published Desktop Statistics"

Write-Output $totalsPD |Format-Table“`This is the result of the script:


You just need to replace a few fields to make it an Horizon script 😉Oh that is wonderful. Thank you for sharing, @member!


I like it, thanks for sharing!


Invoke-CUQuery defaults to the first 1000. You’ll want to play around with paging (-take and -skip)


If you have more than 1000 published apps and desktops, switch to export-cuquery. Thanks @member


$sessions = (Invoke-CUQuery -Scheme Main -Table Sessions -Fields sUserName, xdApplicationsInUse, xdDeliveryGroup, sApplication -where "xdProtocol = ‘HDX’" ).Data


lots of people have more than 1000 sessions thoughAh, yes. I will need to rewrite that part


Very Cool. Thanks for sharing it.


Up nortn… must be Groningen 😉 .. thanks for the script, nice


@member I will give you a tip. It’s colors are blue and yellow 😉


I think I know 😉


@member @member @member I changed the script to allow for large amounts of sessions. the #Fetch all citrix sessions part is replaced by this:

“`$reportdownload = Export-CUQuery -Scheme Main -Table Sessions -Fields sUserName, xdApplicationsInUse, xdDeliveryGroup, sApplication -where "xdProtocol = ‘HDX’"

$sessions = import-csv ($reportdownload.FullFilePath) #import the data generated by the Export-CUquery cmdlet

Get-ChildItem ($reportdownload.FullFilePath) | Remove-Item -force #remove the csv from the Export-CUquery cmdlet“`


As you can see I relaced Invoke-CUQuery (which will load dat into a var) with Export-CUQuery, which will give you a file (FullFilePath) to import the data from.

Continue reading and comment on the thread ‘Script for Monitoring Published App and Desktop Session Statistics with ControlUp’.  Not a member? Join Here!


Categories: All Archives, ControlUp Scripts & Triggers
Topics: Citrix, Citrix HDX, ControlUp Monitor, PowerShell, Reporting, Scripts

Ask Us Anything, Connect, Learn, and Grow with the ControlUp Community!

Login to the ControlUp Community to ask us anything, stay up-to-date on what’s new and coming soon and meet other like-minded techies like you.

Not already a member? Join Today!

Primary Sidebar

ControlUp Academy

Enroll in ControlUp Academy for expert-led technical training, equipping you with skills to effectively deploy, manage, and grow your ControlUp investment.

Learn here >

Rotating Images

Hidden Gem from our Community on Slack!

ControlUp Betas - What's Coming Next?
NEW ControlUp Features - Stay Up-to-Date!
ControlUp Scripts - Scripting, Zero to Hero
Latest KB Articles - Be the First to Learn

Video Tutorials Library

Visit our technical how-to videos, offering step-by-step tutorials on advanced features, troubleshooting, and best practices.

Watch here >

ControlUp Blog

Check out the ControlUp blog for expert advice and in-depth analysis.

Read here >

ControlUp Script Library

Visit the ControlUp technical script library, which offers a multitude of pre-built scripts and custom actions for your monitoring and troubleshooting requirements.

See here >

ControlUp Support

Visit the ControlUp support home and to delve deeper into ControlUp DEX solutions.

Browse here >

Footer

      

ControlUp Community
Of Techie, By Techie, For Techie!

Terms of Use | Privacy Policy | Security
Dive Deeper, Learn more at ControlUp.com

  • facebook
  • twitter
  • youtube
  • linkedin

© 2023–2026 ControlUp Technologies LTD, All Rights Reserved.

We use cookies to ensure that we give you the best experience on our website. by continuing to use this site you agree to our Cookie policy..