Powershell“启动过程”不按计划任务运行

有两个PowerShell脚本,我编辑从XP运行在Win Server 2K8 R2。

它们在通过手动方式在PowerShell中执行时运行良好,但如果按照域pipe理员的计划和运行,它们将执行所有文件操作; 除非他们不做一个启动进程,将文件发送到它需要去的SFTP站点。

它们是通过运行带有参数的powershell.exe启动的:

-noprofile -ExecutionPolicy Bypass -file C:\Users\administrator\Documents\script1.ps1 

同样,就像我之前提到的那样,它们运行良好,并按照要求start-process ,如果您手动运行它们,并且只在计划时运行文件操作并跳过启动进程。

start-process如下:

 start-process -FilePath "c:\Program Files (x86)\Tumbleweed\STClient\stclient.exe" -ArgumentList "httpsu://www.securesiteexample.org/incoming/ $filename /prefNoAskSched /hidden /log /Remote-Site return /quitWhenDone" 

我错过了什么?

添加一些代码来检查以确保该过程正在启动。

 $FileName = 'c:\test\test.txt'; $ArgumentList = "httpsu://www.securesiteexample.org/incoming/ $filename /prefNoAskSched /hidden /log /Remote-Site return /quitWhenDone"; $ExePath = 'c:\Program Files (x86)\Tumbleweed\STClient\stclient.exe'; $Process = Start-Process -FilePath $ExePath -ArgumentList $ArgumentList -PassThru; # If $Process variable is null, then something went wrong ... if (!$Process) { # Process did not start correctly! Write the most recent error to a file Add-Content -Path $env:windir\temp\sftp.log -Value $Error[0]; } 

在您的任务中,转到操作窗格,编辑并从字段中的开始删除任何东西。