I'm porting some old code from AutoHotkey 'for laughs' and think I've stumbled across an unintended feature it had...
I'm wanting to be able to do something 'like'
$ws = "Minimized"
$parameters = "/k dir F:\"
start-process cmd.exe ( $(if($parameters){"-argumentlist $parameters"}) )( $(if ($ws){"-windowystyle $ws"}) )
But it never 'concatenates' them into the one command 'holistically' without also throwing them all at cmd.exe - I'm naively hoping Powershell can 'catch' the WindowStyle itself, for example, and minimize the window (currently, it's passed straight to cmd.exe which ignores it).
I know I'm a bit mad, but I'm also struggling to find the right terms to search for - about_parsing wasn't helpful and the bazillion examples of concatenating strings is no good either - I'm really wanting Powershell to be loose enough to allow me to switch from strings to parameters dynamically, which I'm guessing goes against a conscious design decision somewhere...
So the alternative is a bunch of if statements to accommodate the various permutations of options...
if ($ws -and -(not $parameters)) {start-process cmd.exe -windowystyle $ws}
if ($parameters -and -(not $ws)) {start-process cmd.exe -argumentlist $parameters}
if ($parameters -and $ws) {start-process cmd.exe -argumentlist $parameters -windowystyle $ws}
...ad nauseum
Unless someone's got any better ideas?