The function below returns a result, but when I specify the value in an IF statement, it just return "Yes" whatever I put in the -eq value.
function GetRemoteLogonStatus ($computer = 'localhost') {
if (Test-Connection $computer -Count 2 -Quiet) {
try {
$user = $null
$user = gwmi -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" }
}
if (getremotelogonstatus -eq "blah blah blah")
{
write-host "Yes"
}
Else
{
Write-Host "no"
}
Thanks