From c0acdf38ed4c7793407c6a44b9fe442cddaffd0c Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Thu, 11 Dec 2025 17:13:15 -0500 Subject: [PATCH] Update samy.ps1 --- samy-old.ps1 => samy.ps1 | 48 ++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 22 deletions(-) rename samy-old.ps1 => samy.ps1 (99%) diff --git a/samy-old.ps1 b/samy.ps1 similarity index 99% rename from samy-old.ps1 rename to samy.ps1 index 92560cf..44af1d1 100644 --- a/samy-old.ps1 +++ b/samy.ps1 @@ -2929,32 +2929,36 @@ function Install-DattoRMM { } - if ($MyInvocation.InvocationName -eq '.') { - # dot-sourced, don't invoke -} elseif ($PSCommandPath) { - # script was saved and run directly +if ($MyInvocation.InvocationName -eq '.') { + return # dot-sourced, just define the function +} + +if ($PSBoundParameters.Count -gt 0) { + # Called like: & scriptblock -SilentInstall Invoke-ScriptAutomationMonkey @PSBoundParameters -} else { - # iwr | iex fallback - if ($args.Count -gt 0) { - # Convert -Param value -Switch into a hashtable for splatting - $namedArgs = @{} - for ($i = 0; $i -lt $args.Count; $i++) { - if ($args[$i] -is [string] -and $args[$i].StartsWith('-')) { - $key = $args[$i].TrimStart('-') - $next = $args[$i + 1] - if ($next -and ($next -notlike '-*')) { - $namedArgs[$key] = $next - $i++ # Skip next one, it's the value - } else { - $namedArgs[$key] = $true - } +} +elseif ($args.Count -gt 0) { + # Old-style args: script.ps1 -SilentInstall MyOtherParam value + $namedArgs = @{} + for ($i = 0; $i -lt $args.Count; $i++) { + if ($args[$i] -is [string] -and $args[$i].StartsWith('-')) { + $key = $args[$i].TrimStart('-') + $next = if ($i + 1 -lt $args.Count) { $args[$i + 1] } else { $null } + + if ($next -and ($next -notlike '-*')) { + $namedArgs[$key] = $next + $i++ + } else { + $namedArgs[$key] = $true } } - Invoke-ScriptAutomationMonkey @namedArgs - } else { - Invoke-ScriptAutomationMonkey } + + Invoke-ScriptAutomationMonkey @namedArgs +} +else { + # No params: default to UI + Invoke-ScriptAutomationMonkey }