Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store powershell output in a variable in CMD

In a batchfile, how do I store the output of a powershell command in a variable This isn't working

set yest=powershell get-date((get-date).addDays(-1)) -uformat "%Y%m%d"


powershell get-date((get-date).addDays(-1)) -uformat "%Y%m%d"

gives 20130623

set yest=powershell get-date((get-date).addDays(-1)) -uformat "%Y%m%d"
echo %yest%

gives powershell get-date((get-date).addDays(-1)) -uformat "md"

like image 635
Ank Avatar asked Apr 20 '26 23:04

Ank


1 Answers

The closing braces and percent need to be escaped/doubled.

@echo off
for /f "delims=" %%a in ('powershell get-date((get-date^).addDays(-1^)^) -uformat "%%Y%%m%%d"') do set d8=%%a
echo %d8%
pause
like image 183
foxidrive Avatar answered Apr 23 '26 17:04

foxidrive



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!