forked from gangstanthony/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-LogonStatus.ps1
More file actions
30 lines (25 loc) · 823 Bytes
/
Get-LogonStatus.ps1
File metadata and controls
30 lines (25 loc) · 823 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
# https://gallery.technet.microsoft.com/scriptcenter/Get-Remote-Logon-Status-d8c2318a
function Get-LogonStatus ($computer = $env:COMPUTERNAME) {
$hash = @{
Computer = $computer
Name = '-'
User = '-'
Status = '-'
}
$obj = gwmi win32_computersystem -ComputerName $computer -ea 0
$hash.User = $obj.username
$hash.Name = $obj.name
try {
epsr $computer
if ($hash.User -notmatch '^(?:-|not logged on)$' -and (Get-Process logonui -ComputerName $computer -ErrorAction Stop)) {
$hash.Status = 'Locked'
}
} catch {
if ($hash.User -notmatch '^(?:-|not logged on)$') {
$hash.Status = 'Logged on'
} else {
$hash.Status = 'Not logged on'
}
}
New-Object psobject -Property $hash
}