A job is scheduled to run at logon of the regular user, but using an account of the local administrator.
The script is executed from the file and contains/produces errors. For example:
*) Join-Path uses $home, but $home is null (local administrator is not logged on);
*) NET USE doesn't succeed and gives an error message.
Question: why are all the errors, that occur during the execution of the script, added together at the end of the results, regardless of when and where the errors actually happened? Is there a workaround/setting for this behaviour?
For example, the following script:
Echo "Before Join" $a = Join-Path -Path $home -ChildPath "somestring" Echo "After Join" Echo "a is:" $a Echo "The end."
produces the following results, when examined with Receive-Job:
Before Join After Join a is: The end. Receive-Job : Cannot bind argument to parameter 'Path' because it is an empty string. At line:1 char:1 [...]
Question: what is the recommended/good way of logging the activity of the Scheduled Jobs in actual execution order, including errors?
Regards!