Windows
banshee/windows-collection/windows/winrm/
sessions
The sessions open on a Windows, in use and disconnected, by WinRM and PowerShell
by banshee1 installation2 versions
v2Latest
Published on October 28, 2026. One naming convention across collections; documentation completed.
// The sessions open on a Windows, by WinRM: those in use, at the console as by Remote Desktop, and those
// left disconnected, which keep their programs and their memory.
// Runs one PowerShell script that only reads the counters of the Terminal Services object,
// Win32_PerfRawData_LocalSessionManager_TerminalServices: ActiveSessions and InactiveSessions. Their names
// are English whatever the language of Windows, where the output of quser is translated.
// The script is the one of windows/ssh/sessions, without the powershell -Command "..." that cmd.exe needs
// there.
need('protocol:winrm');
output('sessions', 'number', array('label' => 'Open sessions'));
output('active', 'number', array('label' => 'Sessions in use'));
output('disconnected', 'number', array('label' => 'Disconnected sessions'));
// No threshold by default: what is normal depends on the server, a jump host or a server without sessions.
watch.above('too-many', 'Too many open sessions', 'sessions', array('enabled' => false));
watch.above('disconnected', 'Disconnected sessions left open', 'disconnected', array('enabled' => false));
$read = winrm.run("Get-CimInstance Win32_PerfRawData_LocalSessionManager_TerminalServices"
. " | Select-Object ActiveSessions, InactiveSessions | ConvertTo-Json -Compress");
$answer = text.trim($read['output']);
if (list.count(text.match($answer, '^\{')) == 0) {
fail('misconfigured', 'PowerShell did not return the Terminal Services counters', $answer . $read['errors']);
}
$counters = json.read($answer);
value('active', $counters['ActiveSessions']);
value('disconnected', $counters['InactiveSessions']);
value('sessions', $counters['ActiveSessions'] + $counters['InactiveSessions']);