I need to check if a Domain User is logged on a server. The following can't seem to match the pattern for the user but the variables seems to be okay. The result is always false. I've tried using match, like, contains.
$server = "ServerA"
$ADUser = "CONTOSO\UserA"
$Loggedin = Get-WmiObject win32_computersystem -computer $server | select username
echo $server
echo $ADUser
echo $Loggedin
If ($Loggedin -match $ADUser) {write-host "yes"} ELSE {write-host "no"}