Determine remote windows screen locked or unlocked remotely
I am unable to query if the workstation is LOCKED/UNLOCKED
Use the following PowerShell Script (GetRemoteLogonStatus.ps1).
This script will return the logon status of the local or a remote machine. Return types include "Not logged on", "Locked", "Logged on", and "Offline. The most useful part of this is to check whether a computer is in the locked state, although the other return types could also be useful.
This is a simple function, and can easily be included in a larger script. The return types could be changed to numbers for the calling script to more easily parse the return value.
# This function will return the logged-on status of a local or remote computer # Written by BigTeddy 10 September 2012 # Version 1.0 # Sample usage: # GetRemoteLogonStatus '<remoteComputerName>' function GetRemoteLogonStatus ($computer = 'localhost') { if (Test-Connection $computer -Count 2 -Quiet) { try { $user = $null $user = gwmi -Class win32_computersystem -ComputerName $computer | select -ExpandProperty username -ErrorAction Stop } catch { "Not logged on"; return } try { if ((Get-Process logonui -ComputerName $computer -ErrorAction Stop) -and ($user)) { "Workstation locked by $user" } } catch { if ($user) { "$user logged on" } } } else { "$computer Offline" } }
Source Get Remote Logon Status - Powershell
I forgot to update the post. Since I am using my Ubuntu box to manage most of the Active Directory functions using Webmin/BASH scripts, therefore I made a small bash script which queries for remote windows logged in user session and windows locked/unlocked status.
Result:
root@linux:/temp# /temp/winuserstatus.sh WORKSTAION-1
Remote PC = WORKSTAION-1
IP Details =
Address: 10.0.0.20
Address: 10.0.0.21
User Status = Logged in User found ... details as below ...
jahan.zaib console 13 Active 1+00:53 1/23/2017 1:57 PM
Windows Status = Windows is LOCKED
The bash script does the following …
- Check for remote PC PING Status, if ping fails, exit with error
Get remote windows IP via NSLOOKUP using local DNS
Current Logged-in user and their status
Current status of windows either its locked/unlocked.
TRIM the results and display according to our taste
I posted it details here