arashzgh arashzgh - 3 months ago 39
PowerShell Question

how i can start process with large multiline script block in powershell?

i wanna start process powershell with script block .
like this code.

start-process powershell.exe -ArgumentList "-noexit","-command {
set-Set-ExecutionPolicy bypass -force
get-help get-process
get-command -commandtype cmdlet
...
}"

Answer

The argument for Command should be another element in the ArgumentList not merged into -command.

i.e.

Start-Process powershell.exe -ArgumentList "-noexit", "-command", "Get-Process"

This applies whether the thing you're executing is a simple command or a longer command (a very long string).

Comments