将powershell命令的输出存储在变量中

deb*_*bal 4 powershell batch-file

以下内容:

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

echo %sun %
Run Code Online (Sandbox Code Playgroud)

回声的输出是

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

如何让它输出类似的东西

22九月2013

Joe*_*oey 8

你需要使用for /f:

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