I have a Powershell script, which is working just fine, when called from command line, but only partially fine when executed by the Windows Task Scheduler. The script looks as follows:
# Do things, which are always working.
$session = new-pssession -computername SRV
Invoke-Command -session $session -scriptblock { D:\script.bat }
# Do things, which are always working.
The task defined in the Task Scheduler is completed without errors. As you see, all parts before and after Invoke-Command
are working, also when called by the Task Scheduler. Only the Invoke-Command
itself is only working when called from the command line.
My only guess is, that the Powershell script is exiting prematurely, but I didn't find any way to confirm this or even solve the issue.
it is likely to be a permissions issue - as a test, run the task using the same credentials as when it is run at the command line...