Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 208
debal Avatar asked Jan 13 '23 06:01

debal


1 Answers

You need to use for /f:

for /f "usebackq" %%x in (`powershell "(Get-Date).AddDays(-8).ToString('dd-MMM-yyyy')"`) do set sun=%%x
like image 104
Joey Avatar answered Feb 22 '23 00:02

Joey