PowerShell Invoke-Expression with ampersand in the command string PowerShell Invoke-Expression with ampersand in the command string powershell powershell

PowerShell Invoke-Expression with ampersand in the command string


The ampersand must be double-quoted inside the string "&", so you need to escape the inner double quotes

$streamout_calmedia01 = "rtmp://...vent`"&`"adbe-record-mode=record"

or put the string in single quotes

$streamout_calmedia01 = 'rtmp://...vent"&"adbe-record-mode=record'


Change $streamout_calmedia01 to:

$streamout_calmedia01 = "rtmp://75.126.42.216/livepkgr/calmedialive01?adbe-live-event=liveevent```&adbe-record-mode=record"

Then you have to re-assign $streamout_calmedia1 (with the new value of $streamout_calmedia1) and it should work.


You don't need to be using Invoke-Expression at all. Avoiding its use will preclude the issue. Just call the EXE file tool directly:

$streamout_calmedia01 = "rtmp://75.126.42.216/livepkgr/calmedialive01?adbe-live-event=liveevent&adbe-record-mode=record"C:\avconv\usr\bin\avconv.exe 'rtmp://75.126.42.211/transcoder/mobileingest live=1' -f flv -c:v libx264 -r 30 -g 120 -b:v 410000 -c:a aac -ar 22050 -b:a 64000 -strict experimental -y $streamout_calmedia01

This avoids all of the complications of double-escaping and should do what you are intending.