I am trying to schedule a simple script that will test whether a user is logged on or not, and send an email if not.
$user = get-wmiobject win32_computersystem -computer computername | Select-Object -ExpandProperty username
if ($user -ne "domain\user") {
send-mailmessage .....
}
When I run it from ISE or cmd I do not get an email so long is desired user is logged in, however if I run as a scheduled task I always get an email regardless of whether the user is logged in.
-It is schedule to run as SYSTEM with highest priveleges
-Localmachine execution policy is RemoteSigned
-Action is powershell -file "C:\scripts\file.ps1"
Any advice would be appreciated!