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