Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file assign returned values from a command into a variable (from powershell)

i am refering to this question ASSIGN win XP commandline output to variable

i am trying to use it on a powershell code segment so i typed

powershell date (get-date).AddDays(-1) -format yyyyMMdd

and confirm it returns like

20100601

but then if i tried to

for /f "tokens=*" %a in ('powershell date get-date -format yyyyMMdd
') do set var=%a

then it failed to work as expected. how can i transfer the date to a variable?

like image 514
nokheat Avatar asked Jul 21 '26 00:07

nokheat


1 Answers

Maybe

for /f "tokens=*" %a in ('powershell "get-date; get-date -format yyyyMMdd"') do set var=%a

is what you wanted.

like image 193
stej Avatar answered Jul 23 '26 15:07

stej