将powershell命令的输出存储在变量中 [英] store the output of powershell command in a variable

查看:37
本文介绍了将powershell命令的输出存储在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令:

$sun=PowerShell [DateTime]::Today.AddDays(-8).ToString('dd-MMM-yyyy')

echo %sun %

回声的输出是

PowerShell [DateTime] :: Today.AddDays(-8).ToString('dd-MMM-yyyy')

PowerShell [DateTime]::Today.AddDays(-8).ToString('dd-MMM-yyyy')

如何获取类似

2013年9月22日

22-Sep-2013

推荐答案

您需要将用于/f :

for /f "usebackq" %%x in (`powershell "(Get-Date).AddDays(-8).ToString('dd-MMM-yyyy')"`) do set sun=%%x

这篇关于将powershell命令的输出存储在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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