Reputation: 6270
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"
Upvotes: 3
Views: 8680
Reputation: 41234
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
Upvotes: 8