store the output of powershell command in a variable

后端 未结 1 957
被撕碎了的回忆
被撕碎了的回忆 2021-01-19 10:26

The following commnad:

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

echo %sun %

the output of the echo is

1条回答
  •  伪装坚强ぢ
    2021-01-19 10:57

    You need to use for /f:

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

    0 讨论(0)
提交回复
热议问题