Why does Start-Process powershell.exe { Read-Host } work, but Start-Process pwsh.exe { Read-Host } does not?
I'm aware of the -ArgumentList switch of Start-Process, but it makes things more complicated when it comes to escaping quotation marks:
PowerShell 7.0.3 and 7.2.0-preview.3:
Start-Process pwsh.exe -ArgumentList '-Command "& {
''Hello World.''
Read-Host
}"' -Verb RunAs
PowerShell 5.1:
Start-Process powershell.exe {
'Hello World.'
Read-Host
} -Verb RunAs
On the other hand, when creating a new PowerShell session (without Start-Process), it is still possible to use a script block:
pwsh.exe {
'Hello World.'
Read-Host
}
Am I missing something here or is there a better/different approach which allows a script block to be executed parallel to the rest of a script?