Metric for knowing if a Win server has remote logged in users?

I’m trying to establish a metric of the number of remote logged in users in Windows servers.

I’m trying to do it through WMI, but still working on how to do it…

Has anyone managed to do this?

Just to give Feedback on how I managed to do it. Used query below to grab number of active sessions in Terminal Services, and then coded a v2 extension:

$computerName = "192.168.111.20"
$credential = Get-Credential 
Get-WmiObject -Class Win32_PerfFormattedData_LocalSessionManager_TerminalServices -ComputerName $computerName -Credential $credential | Select-Object -ExpandProperty ActiveSessions