escaping powershell in batch loop
Posted: 25 Jul 2023 10:33
have following loop
but got error
On command line, powershell command work fine. Trying to escape some dashes and semicolon, but have no luck. What could cause this error?
Code: Select all
for /f "tokens=1-3 delims=- " %%a in ('
powershell.exe -Command "Get-EventLog -ErrorAction SilentlyContinue -Newest 1 -LogName System -EntryType Error -Source Tcpip | ForEach-Object { \"$(Get-Date $_.TimeGenerated) - $($_.ReplacementStrings -join '#')\" }; Write-output ^$error[0]"
') do (
echo %%a %%b %%c
)
Code: Select all
- was unexpected at this time.