Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Script produces different result when run as a scheduled task than run from ISE

$
0
0

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!  



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>