Skip to content

Commit 52de469

Browse files
authored
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
1 parent ef97a8d commit 52de469

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

scripts/start.ps1

+13-7
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,27 @@ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]:
5454
$PSBoundParameters.GetEnumerator() | ForEach-Object {
5555
$argList += if ($_.Value -is [switch] -and $_.Value) {
5656
"-$($_.Key)"
57+
} elseif ($_.Value -is [array]) {
58+
"-$($_.Key) $($_.Value -join ',')"
5759
} elseif ($_.Value) {
58-
"-$($_.Key) `"$($_.Value)`""
60+
"-$($_.Key) '$($_.Value)'"
5961
}
6062
}
6163

62-
$script = if ($MyInvocation.MyCommand.Path) {
63-
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
64+
$script = if ($PSCommandPath) {
65+
"& { & `'$($PSCommandPath)`' $($argList -join ' ') }"
6466
} else {
65-
"iex '& { $(irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1) } $argList'"
67+
"&([ScriptBlock]::Create((irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1))) $($argList -join ' ')"
6668
}
6769

68-
$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
69-
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }
70+
$powershellCmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
71+
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { "$powershellCmd" }
7072

71-
Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command $script" -Verb RunAs
73+
if ($processCmd -eq "wt.exe") {
74+
Start-Process $processCmd -ArgumentList "$powershellCmd -ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs
75+
} else {
76+
Start-Process $processCmd -ArgumentList "-ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs
77+
}
7278

7379
break
7480
}

0 commit comments

Comments
 (0)