I have a lot of scripts that are running as scheduled tasks. So they do a $host.setshouldexit(1)
on any failure, which shows up in the task scheduler as the return code.
I also want to be able to run these scripts interactively while debugging and testing. So the $host.setshouldexit()
kills my powershell or ISE session.
My question is: how can I detect if a script is running non-interactively? If it is, then I'll use setshouldexit
, otherwise it will print the error code or something nondestructive. (Note that I don't want to use [environment]::userinteractive
because these scripts are not always running in what the OS thinks is a non-interactive session.)
There is a -noninteractive switch that I'm using for the scheduled tasks. Is there some way I can query that from powershell?