I have a Master script that has several options. When you select 1 in the menu, action 1 will be executed and afterwards you\'ll get back to the menu. This
Although start powershell
command looks cleaner, it doesn't allow you to do everything that you can do with invoke-expression
. For example, the following opens a new window, changes its title and background color, and leaves the window open:
invoke-expression 'cmd /c start powershell -NoExit -Command { `
cd -path $env:homedrive$env:homepath/Documents/MySillyFolder; `
$host.UI.RawUI.WindowTitle = "A Silly Little Title"; `
color -background "red"; `
}';
It also runs fine from within another powershell script.
If you try to do this using the start powershell {...}
syntax it will give an error on the title-changing line, and won't keep the window open. (I suppose It's possible that there's some obscure syntax hack that will make start powershell
work, but I haven't been able to find one.)