Powershell:
line1
line2
line3
line4
Excel VBA:
Set objShell = CreateObject("Wscript.Shell")
objShell.Run ("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -executionpolicy bypass -command ""line1; line2; lin3; line4"")
line1
will run and open a powershell window but the rest of the commands do not run. I can copy and paste each of line2
, line3
and line4
individually into the powershell window at the prompt and they will each run.
I suggest using powershell's
-EncodedCommand
parameter.From their help documentation (
powershell -?
):To generate the base64 for the parameter (shortened):
In action:
Note: This will fail with
'line1' is not recognized
since I took your example literally.