From 52de4690aba907f911e92afb4a6bcede2a58d684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20W=C3=B3jcik?= <34631176+emilwojcik93@users.noreply.github.com> Date: Wed, 5 Mar 2025 19:15:13 +0100 Subject: [PATCH] Update start.ps1 (#3223) - use join method to parse $argList - use $PSCommandPath instead of $MyInvocation.MyCommand.Path - use ScriptBlock method to create request for latest winutil.ps1 with join $argList - condition for $processCmd because in case when wt.exe is not available, there was double/redundant declaration of shell which lead to code mishmash (incorrect interpretation of quotes from Start-Process ArgumentList parameters - changes in quotes and escape characters because command where not interpreted correctly in all possible cases of $powershellCmd and $processCmd --- scripts/start.ps1 | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/start.ps1 b/scripts/start.ps1 index 2e55646b..209eb952 100644 --- a/scripts/start.ps1 +++ b/scripts/start.ps1 @@ -54,21 +54,27 @@ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]: $PSBoundParameters.GetEnumerator() | ForEach-Object { $argList += if ($_.Value -is [switch] -and $_.Value) { "-$($_.Key)" + } elseif ($_.Value -is [array]) { + "-$($_.Key) $($_.Value -join ',')" } elseif ($_.Value) { - "-$($_.Key) `"$($_.Value)`"" + "-$($_.Key) '$($_.Value)'" } } - $script = if ($MyInvocation.MyCommand.Path) { - "& { & '$($MyInvocation.MyCommand.Path)' $argList }" + $script = if ($PSCommandPath) { + "& { & `'$($PSCommandPath)`' $($argList -join ' ') }" } else { - "iex '& { $(irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1) } $argList'" + "&([ScriptBlock]::Create((irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1))) $($argList -join ' ')" } - $powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" } - $processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd } + $powershellCmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" } + $processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { "$powershellCmd" } - Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command $script" -Verb RunAs + if ($processCmd -eq "wt.exe") { + Start-Process $processCmd -ArgumentList "$powershellCmd -ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs + } else { + Start-Process $processCmd -ArgumentList "-ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs + } break }