You can add ' ^' to continue the string that you are assigning to a variable. This creates the command as a single line, so you need to use ';' between statements:
@ECHO off
SET LONG_COMMAND= ^
if ($true) ^
{ ^
Write-Host "Result is True"; ^
Write-Host "Multiple statements must be separated by a semicolon." ^
} ^
else ^
{ ^
Write-Host "Result is False" ^
}
START Powershell -noexit -command %LONG_COMMAND%
If the only code you need to execute is PowerShell, you can use something like:
;@Findstr -bv ;@F "%~f0" | powershell -command - & goto:eof
if ($true){
Write-Host "Result is True" -fore green
}
else{
Write-Host "Result is False" -fore red
}
Start-Sleep 5
which pipes all lines not starting with ";@F" to PowerShell.
Edit: I was able to start PowerShell in a separate window and allow cmd to exit with this:
@@ECHO off
@@setlocal EnableDelayedExpansion
@@set LF=^
@@SET command=#
@@FOR /F "tokens=*" %%i in ('Findstr -bv @@ "%~f0"') DO SET command=!command!!LF!%%i
@@START powershell -noexit -command !command! & goto:eof
if ($true){
Write-Host "Result is True" -fore green
}
else{
Write-Host "Result is False" -fore red
}
Note that there must be 2 spaces after setting the 'LF' variable since we are assigning a line feed to the variable.