-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b76c90
commit 8c70cbd
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<# | ||
.Synopsis | ||
This function will return the logged-on status of a local or remote computer | ||
.EXAMPLE | ||
GetRemoteLogonStatus test-computer | ||
#> | ||
function Get-RemoteLogonStatus | ||
{ | ||
# Param ( | ||
# [string[]]$computerName = 'localhost' | ||
#) | ||
$computerName = Get-Content "C:\serverlist.txt" | ||
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 | ||
#$user = Get-CimInstance -Class win32_computersystem -ComputerName $c | select -ExpandProperty username -ErrorAction Stop | ||
} | ||
catch { "Not logged on to $c"; return } | ||
try { | ||
if ((Get-Process logonui -ComputerName $c -ErrorAction Stop) -and ($user)) { | ||
"$c locked by $user" | ||
} | ||
} | ||
catch { if ($user) { "$user logged on to $c" } } | ||
} | ||
else { "$c Offline" } | ||
} | ||
} | ||
|
||
Get-RemoteLogonStatus |