diff --git a/samy.ps1 b/samy.ps1 index d4867c3..92560cf 100644 --- a/samy.ps1 +++ b/samy.ps1 @@ -158,24 +158,43 @@ $Script:SamyBranch = 'beta' # or 'main' #> #region Safely bypass Restricted Execution Policy # ─── Safely bypass Restricted Execution Policy ─── +#region Safely bypass Restricted Execution Policy +# Safely bypass Restricted Execution Policy if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage' -or (Get-ExecutionPolicy) -eq 'Restricted') { Write-Host "[Info] Relaunching with ExecutionPolicy Bypass..." -ForegroundColor Yellow + # Rebuild the original argument list as a string to pass through + $argList = @() + foreach ($a in $args) { + if ($a -is [string]) { + # Quote and escape any existing quotes + $escaped = $a.Replace('"','`"') + $argList += "`"$escaped`"" + } else { + $argList += $a.ToString() + } + } + $argString = $argList -join ' ' + if ($PSCommandPath) { - powershell.exe -NoProfile -ExecutionPolicy Bypass -File "`"$PSCommandPath`"" + # Script saved on disk: re-run same file with same args + powershell.exe -NoProfile -ExecutionPolicy Bypass -File "`"$PSCommandPath`"" $argString } else { - powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& { iwr 'https://samy.svstools.com' -UseBasicParsing | iex }" + # iwr | iex scenario: re-download SAMY and apply same args + powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& { iwr 'https://samy.svstools.ca' -UseBasicParsing | iex } $argString" } exit } -# ─── TLS and silent install defaults ─── +# TLS and silent install defaults [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $ProgressPreference = 'SilentlyContinue' $ConfirmPreference = 'None' +#endregion Safely bypass Restricted Execution Policy + #endregion Safely bypass Restricted Execution Policy function Invoke-ScriptAutomationMonkey {