store the output of powershell command in a variable

*爱你&永不变心* 提交于 2021-01-20 05:02:59

问题


The following commnad:

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

echo %sun %

the output of the echo is

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

how do i get it to output something like

22-Sep-2013


回答1:


You need to use for /f:

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


来源:https://stackoverflow.com/questions/19089736/store-the-output-of-powershell-command-in-a-variable

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