You may use the following Microsoft Windows PowerShell script to query a remote server and display any logged on users.

<# .SYNOPSIS This script will query a remote server and display user session information. .DESCRIPTION This script will query a remote server and display user session information. .EXAMPLE N/A. .AUTHOR Written by Noel Enrique Alvarez on Monday, April 15, 2019. #>

#Request the hostname of the server
$HOSTNAME = Read-Host “What is the hostname of the server?”

#Query the remove server
query user /server:$HOSTNAME

#End of script