-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathGetRemoteLogonStatus.ps1
More file actions
37 lines (32 loc) · 966 Bytes
/
Copy pathGetRemoteLogonStatus.ps1
File metadata and controls
37 lines (32 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Written by BigTeddy 10 September 2012
# Version 1.0
# Ammended by Jackbennett 13/01/14
<#
.Synopsis
This function will return the logged-on status of a local or remote computer
.EXAMPLE
GetRemoteLogonStatus test-computer
#>
function GetRemoteLogonStatus
{
Params(
[string[]]$computerName = 'localhost'
)
foreach( $c in $computerName)
{
if (Test-Connection $c -Count 2 -Quiet) {
try {
$user = $null
$user = gwmi -Class win32_computersystem -ComputerName $c | select -ExpandProperty username -ErrorAction Stop
}
catch { "Not logged on"; return }
try {
if ((Get-Process logonui -ComputerName $c -ErrorAction Stop) -and ($user)) {
"Workstation locked by $user"
}
}
catch { if ($user) { "$user logged on" } }
}
else { "$c Offline" }
}
}