简体   繁体   English

在Powershell脚本中使用批处理创建计划任务

[英]Creating a scheduled task using batch in a powershell script

So I'm trying to create a scheduled task using batch in a powershell script because I cant use the powershell method, due to the fact that my company is using the outdated windows server 2008. For some reason ISE is not finding the new-scheduledtask command. 因此,由于我的公司正在使用过时的Windows Server 2008,因此我无法使用powershell方法,因此我试图在Powershell脚本中使用批处理来创建计划任务。由于某些原因,ISE无法找到new-scheduledtask命令。 Even though I have powershell 4.0 installed and have tried to update the help and nothing works. 即使我已经安装了Powershell 4.0,并尝试更新帮助,但没有任何效果。 Here is what i have so far on creating the scheduled task: 到目前为止,这是我创建计划任务的内容:

&schtasks /create /tn "ExtractSSRSData" /tr "C:\\Program Files\\company\\HTFS.Job.Launcher\\HTFS.Common.Job.Launcher.exe" /sc "DAILY" . &schtasks /create /tn "ExtractSSRSData" /tr "C:\\Program Files\\company\\HTFS.Job.Launcher\\HTFS.Common.Job.Launcher.exe" /sc "DAILY"

For some reason when this creates the task, the path gets cut in half and part goes into the file path field and the other ends up in the arguments field (as screen shot below). 由于某种原因,当创建任务时,该路径被切成两半,一部分进入文件路径字段,另一部分最终进入参数字段(如下面的屏幕截图所示)。 I also don't know the argument to add arguments to a task in batch. 我也不知道将参数批量添加到任务中的参数。 脚本问题

Also i have these arguments that need to go into the add arguments window how do i get them there in batch? 我也有这些参数需要进入添加参数窗口,我如何批量获取它们? SetSSRSDataInDb admin "CompanyCode=company"

It appears that the command and parameters are parsed from the same string, and it splits the command and parameters at the first non-delimited space. 似乎命令和参数是从同一字符串中解析出来的,并且它将命令和参数拆分到第一个非分隔空间。

Delimit the entire string that includes the command and argument in double quotes, and then delimit the path and .exe with single quotes, followed by a space, and then the parameters: 用双引号分隔包括命令和参数的整个字符串,然后用单引号分隔路径和.exe,后跟一个空格,然后输入参数:

&schtasks /create /tn "ExtractSSRSData" /tr "'C:\\Program Files\\company\\HTFS.Job.Launcher\\HTFS.Common.Job.Launcher.exe' SetSSRSDataInDb admin 'CompanyCode=company'" /sc "DAILY"

You can see after running this that if one of the parameters needs to be delimited with quotes ( CompanyCode=company in your example), you just need to use single quotes and it magically delimits the string with double quotes. 运行此命令后,您可以看到,如果其中一个参数需要用引号引起来(在示例中使用CompanyCode=company ),则只需使用单引号并将其魔术地用双引号定界。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM