debal
debal

Reputation: 1017

store the output of powershell command in a variable

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

Upvotes: 4

Views: 5861

Answers (1)

Joey
Joey

Reputation: 354794

You need to use for /f:

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

Upvotes: 9

Related Questions