A batch file assigns return values ​​from a command to a variable (from the command line)

I refer to this question ASSIGN output XP command line output to a variable

I am trying to use it on a powershell code segment so I printed

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

and confirm it as

 20100601 

but if i tried

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

then he did not work properly. How can I transfer the date to a variable?

+3
source share
1 answer

maybe

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

- this is what you wanted.

+5
source

Source: https://habr.com/ru/post/973425/


All Articles