Skip to content

Commit

Permalink
Create Get-RemoteLogonStatus.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorrison42 authored Jul 12, 2018
1 parent 4b76c90 commit 8c70cbd
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Get-RemoteLogonStatus.ps1
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

0 comments on commit 8c70cbd

Please sign in to comment.