Windows脚本更改日期和运行命令 [英] windows script to change date and run command

查看:114
本文介绍了Windows脚本更改日期和运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命令,每天都会使用它来获取审计报告.我想使用命令或脚本在Windows Scheduler中计划它.它可以是.bat或.cmd脚本.命令是:

I have a command which i am using to get audit report on daily basis. I want to schedule it in windows scheduler using the command or script. It can be .bat or .cmd scripting. The command is :

<Install_Path>\nbauditreport.exe -sdate "MM/DD/YY 00:00:00" -edate "MM/DD/YY 23:59:59"

因此,在此命令中,所有内容都相同,剩下MM,DD和YY.那么如何从命令中替换日,月和年?

So in this command everything will be same leaving MM, DD and YY. So how can i replace day, month and year from the command?

日期是当前日期的前一天.例如,该命令计划于2017年7月7日上午09:00运行,在这种情况下,该命令将为:

The date is one day previous date of current. For example, the command is scheduled to run on 07 July 2017 at 09:00 AM, In that case the command will be:

<Install_Path>\nbauditreport.exe -sdate "07/06/17 00:00:00" -edate "07/06/17 23:59:59"

如何为该脚本创建脚本?

How can I create the script for the same?

推荐答案

您的掩码"MM/DD/YY"是一年中的两位数字吗?
然后在接下来的批次中将其更改为仅两个yy,但保持原样.

Is your mask "MM/DD/YY" meant to have only 2 digits for the year?
Then change in the following batch to only two yy but leave the casing as is.

@echo off
For /f %%Y in (
  'powershell -NoP -C "(get-date).AddDays(-1).ToString(\"MM\/dd\/yy\")"'
) Do Set Yesterday=%%Y
"X:\Path\to\nbauditreport.exe" -sdate "%Yesterday% 00:00:00" -edate "%Yesterday% 23:59:59"

安排此批次.

这篇关于Windows脚本更改日期和运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆