From ffab89a69a466190c845cfd5086a5356e96492dc Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sun, 29 Jun 2025 13:46:05 -0400 Subject: [PATCH] moved #region ScriptMonkey run silently Entrypoint --- StackMonkey.ps1 | 134 ++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 68 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index 6f4cfc7..dff4382 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -1,9 +1,5 @@ # region changes to be done -# if (Get-Command msedge.exe -ErrorAction SilentlyContinue) { -# Start-Process msedge.exe -ArgumentList "--app=http://localhost:$Port" -#} else { -# Start-Process "microsoft-edge:http://localhost:$Port" -#} + #endregion <# @@ -122,6 +118,71 @@ [Parameter(ParameterSetName='DattoInstall')][switch] $SaveCopy ) + #region ScriptMonkey run silently Entrypoint + + # ───────────────────────────────────────────────────────────────────────── + # 3) MAIN LOGIC (Toolkit vs DattoFetch vs DattoInstall vs UI) + # ───────────────────────────────────────────────────────────────────────── + + switch ($PSCmdlet.ParameterSetName) { + 'Toolkit' { + Write-LogHybrid "Toolkit-only mode" Info Startup + Install-SVSMSP -InstallToolkit + return + } + + # ─────────────────────────────────────────────────────────── + # 2) If user only wants the site list, do that and exit + # ─────────────────────────────────────────────────────────── + + 'DattoFetch' { + Write-LogHybrid "Fetching site list only…" Info DattoAuth + $sites = Get-DattoRmmSites -Password $N8nPassword + + $ext = [IO.Path]::GetExtension($OutputFile).ToLower() + if ($ext -eq '.json') { + $sites | ConvertTo-Json -Depth 3 | Out-File -FilePath $OutputFile -Encoding UTF8 + } else { + $sites | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8 + } + + Write-LogHybrid "Wrote $($sites.Count) sites to $OutputFile" Success DattoAuth + return + } + + # ──────────────────────────────────────────── + # 3) Invoke the existing Install-DattoRMM cmdlet + # ──────────────────────────────────────────── + + 'DattoInstall' { + Write-LogHybrid "Headless DattoRMM deploy" Info DattoAuth + if ($PSCmdlet.ShouldProcess("Datto site '$SiteName'", "Headless install")) { + Install-DattoRMM ` + -ApiUrl $Global:ApiUrl ` + -ApiKey $Global:ApiKey ` + -ApiSecretKey $Global:ApiSecretKey ` + -SiteUID $SiteUID ` + -SiteName $SiteName ` + -PushSiteVars:$PushSiteVars ` + -InstallRMM:$InstallRMM ` + -SaveCopy:$SaveCopy + } + + return + + } + + 'UI' { + Write-LogHybrid "Launching UI" Info Startup + Write-Host "Starting ScriptMonkey UI on http://localhost:$Port/" -ForegroundColor Cyan + Start-Process "msedge.exe" -ArgumentList "--app=http://localhost:$Port" + Start-Server # blocks until you click Exit + return + } + + } + #endregion ScriptMonkey run silently Entrypoint + Write-Host "ParameterSetName: $($PSCmdlet.ParameterSetName)" -ForegroundColor Yellow #region — guarantee NuGet provider is present without prompting @@ -1501,70 +1562,7 @@ $script #endregion - #region ScriptMonkey run silently Entrypoint - # ───────────────────────────────────────────────────────────────────────── - # 3) MAIN LOGIC (Toolkit vs DattoFetch vs DattoInstall vs UI) - # ───────────────────────────────────────────────────────────────────────── - - switch ($PSCmdlet.ParameterSetName) { - 'Toolkit' { - Write-LogHybrid "Toolkit-only mode" Info Startup - Install-SVSMSP -InstallToolkit - return - } - - # ─────────────────────────────────────────────────────────── - # 2) If user only wants the site list, do that and exit - # ─────────────────────────────────────────────────────────── - - 'DattoFetch' { - Write-LogHybrid "Fetching site list only…" Info DattoAuth - $sites = Get-DattoRmmSites -Password $N8nPassword - - $ext = [IO.Path]::GetExtension($OutputFile).ToLower() - if ($ext -eq '.json') { - $sites | ConvertTo-Json -Depth 3 | Out-File -FilePath $OutputFile -Encoding UTF8 - } else { - $sites | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8 - } - - Write-LogHybrid "Wrote $($sites.Count) sites to $OutputFile" Success DattoAuth - return - } - - # ──────────────────────────────────────────── - # 3) Invoke the existing Install-DattoRMM cmdlet - # ──────────────────────────────────────────── - - 'DattoInstall' { - Write-LogHybrid "Headless DattoRMM deploy" Info DattoAuth - if ($PSCmdlet.ShouldProcess("Datto site '$SiteName'", "Headless install")) { - Install-DattoRMM ` - -ApiUrl $Global:ApiUrl ` - -ApiKey $Global:ApiKey ` - -ApiSecretKey $Global:ApiSecretKey ` - -SiteUID $SiteUID ` - -SiteName $SiteName ` - -PushSiteVars:$PushSiteVars ` - -InstallRMM:$InstallRMM ` - -SaveCopy:$SaveCopy - } - - return - - } - - 'UI' { - Write-LogHybrid "Launching UI" Info Startup - Write-Host "Starting ScriptMonkey UI on http://localhost:$Port/" -ForegroundColor Cyan - Start-Process "msedge.exe" -ArgumentList "--app=http://localhost:$Port" - Start-Server # blocks until you click Exit - return - } - - } - #endregion ScriptMonkey run silently Entrypoint } if ($MyInvocation.InvocationName -eq '.') {