Congrats on the great script. Very useful!
I have added below a script that would be a great addition to your code. It produces the IP address of the workstation connected. I found it at SQL Central. It would helpful if the user is connected with SQL authentication.
What do you think?
SELECT ec.client_net_address AS 'IP Address of Client', es.[program_name] AS 'Name of Application',
es.[host_name] AS 'Host/Computer Name', es.login_name AS 'ID Used',
COUNT(ec.session_id) AS 'Connection Count', @@SERVICENAME AS 'Instance User Is Connected To'
FROM sys.dm_exec_sessions AS es
INNER JOIN sys.dm_exec_connections AS ec
ON es.session_id = ec.session_id
GROUP BY ec.client_net_address, es.[program_name], es.[host_name], es.login_name
ORDER BY ec.client_net_address, es.[program_name]