In a Windows 7 batch file, I can call powershell v2 to create a string and then assign that string to a batch file variable to later use within another command, like this:
for /f "delims=" %%a in ('powershell -noninteractive -NoProfile -Command "Get-Date -format 'yyyy-MM-dd HH_mm_ss'"') do set "datetime=%%a"
rem process file1.txt here
ren file1.txt "newname %datetime%.txt"
If I try to do the same thing (within a batch file), in a simpler way, it doesn't work:
Editor's note: Turns out it does work - the inner "
instances are correctly escaped as \"
.
powershell -noninteractive -NoProfile -Command "$datetime_string = Get-Date -format 'yyyy-MM-dd HH_mm_ss'; (gc file1.txt) -join [char]10 | Out-File -Encoding Ascii \"newname $datetime_string.txt\""
Can you help?