Powershell “Start-process” not running as scheduled task

∥☆過路亽.° 提交于 2019-12-11 09:34:06

问题


Have two powershell scripts that I edited from XP to run in Win Server 2k8 R2.

They run fine when executed by manually in powershell, but if scheduled and run as domain admin, they perform all file operations they're supposed to; except they don't do a start-process that sends the file to the SFTP site it needs to go to.

They're launched by running powershell.exe with arguments as such:

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

Again, like I mentioned previously, they run fine and launch the start-process as requested if you manually run them and only run the file operations if they're scheduled and skip the start-process.

The start-process is as follows:

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"

What am I missing?


回答1:


Add some code to check to make sure the process is getting launched.

$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];
}



回答2:


In your Task, go to Actions pane, edit and remove anything from start in field.



来源:https://stackoverflow.com/questions/23140588/powershell-start-process-not-running-as-scheduled-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!