【发布时间】:2013-06-21 16:11:42
【问题描述】:
在批处理文件中,如何将 powershell 命令的输出存储在变量中 这不起作用
set yest=powershell get-date((get-date).addDays(-1)) -uformat "%Y%m%d"
powershell get-date((get-date).addDays(-1)) -uformat "%Y%m%d"
给20130623
set yest=powershell get-date((get-date).addDays(-1)) -uformat "%Y%m%d"
echo %yest%
给powershell get-date((get-date).addDays(-1)) -uformat "md"
【问题讨论】:
-
您是在 powershell 中使用 echo 还是这两个不同的脚本/控制台?
-
echo 在批处理文件中。我在批处理文件中使用 powershell
-
其实这个好像已经回答了:stackoverflow.com/questions/2955512/…
-
@AthomSfere 它从命令行工作。但是当我把它放在一个批处理文件中时,它给了我一个错误
a was unexpected at this time
标签: powershell windows-7 batch-file cmd