从Windows任务计划程序调用时,Powershell的Invoke-Command无法正常工作

时间:2013-09-03 09:23:09

标签: powershell scheduled-tasks invoke-command

我有一个Powershell脚本,从命令行调用时效果很好,但在Windows任务调度程序执行时只有部分正常。该脚本如下所示:

# 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.

任务计划程序中定义的任务已完成且没有错误。如您所见,Invoke-Command之前和之后的所有部分都在工作,同样在任务计划程序调用时也是如此。只有Invoke-Command本身仅在从命令行调用时才起作用。

我唯一的猜测是,Powershell脚本过早退出,但我没有找到任何方法来确认这一点,甚至没有解决问题。

2 个答案:

答案 0 :(得分:1)

很可能是权限问题 - 作为测试,使用与在命令行运行时相同的凭据运行任务...

答案 1 :(得分:-1)

当我从任务计划程序调用脚本以在多台计算机上运行某些脚本块时,我遇到与Invoke-Command相同的问题。我不知道为什么,但将操作的" Start in" 文件夹设置为脚本的文件夹解决了它。 action configuration window

相关问题