■ 원격 로그온 상태를 구하는 방법을 보여준다.
▶ 원격 로그온 상태 구하기 예제
1 2 3 4 5 |
GetRemoteLogonStatus 'localhost' GetRemoteLogonStatus '127.0.0.1' |
▶ 원격 로그온 상태 구하기
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 36 37 38 39 |
function GetRemoteLogonStatus($computer = 'localhost') { if(Test-Connection $computer -Count 2 -Quiet) { try { $user = $null $user = Get-WmiObject -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" } } |