From 2781493231edddb4c0680aa25dc65a7192ecbb7a Mon Sep 17 00:00:00 2001 From: syelle Date: Fri, 28 Nov 2025 20:11:40 -0500 Subject: [PATCH] added more #regions --- samy.ps1 | 64 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/samy.ps1 b/samy.ps1 index d754563..4d9ab20 100644 --- a/samy.ps1 +++ b/samy.ps1 @@ -4,29 +4,30 @@ ## Last changes made should fix the issues we had wen running thi in Windows 11 25H2 +#region Documentation <# .SYNOPSIS - Script Automation Monkey - MSP client onboarding/offboarding toolkit with a user interface, - and optional silent install of the SVSMSP toolkit and headless DattoRMM deployment. + Script Automation Monkey (SAMY) is a unified MSP assistant that automates onboarding, headless offboarding, + Datto RMM deployments, and toolkit management through a local UI, HTTP endpoints, or direct PowerShell switches. .DESCRIPTION - Install-DattoRMM is a single, unified toolkit for Datto RMM operations. It can be used - interactively or via HTTP endpoints, and includes built-in validation and error trapping. + Install-DattoRMM is the core helper that handles credential retrieval (webhook or direct), OAuth token management, + site list fetching/persistence, registry variable pushes, agent downloads/installs, and optional installer archiving. + The UI exposes all tasks as checkboxes with select-all helpers, and each action is wrapped in detailed logging plus + HTTP responders so callers can see success or failure. Key features: - - Credential retrieval - securely fetches ApiUrl, ApiKey, and ApiSecretKey from a webhook. - - OAuth management - automatically acquires and refreshes bearer tokens over TLS. - - Site list fetching - returns the list of RMM sites; validates OutputFile to .csv or .json. - - Site list saving - writes fetched site list to the user's Desktop as CSV or JSON. + - Credential retrieval - securely fetches ApiUrl, ApiKey, and ApiSecretKey from a webhook when requested. + - OAuth management - automatically acquires and refreshes bearer tokens over TLS to talk to Datto. + - Site list fetching - returns the list of RMM sites and validates OutputFile extensions (.csv/.json). + - Site list persistence - saves fetched site lists to the requester's desktop as CSV or JSON. - Registry variable push - writes site-specific variables under HKLM:\Software\SVS\Deployment. - - Agent download & install - downloads the Datto RMM agent installer and launches it. - - Installer archiving - saves a copy of the downloaded installer to C:\Temp. - - HTTP endpoints - exposes /getpw and /installDattoRMM handlers, each wrapped in try/catch - to log errors and return proper HTTP 500 responses on failure. - - Idempotent & WhatIf support - uses ShouldProcess for safe, testable agent installs. + - Agent download & install - pulls the Datto RMM agent, launches it, and optionally saves a copy to C:\Temp. + - HTTP endpoints - /getpw and /installDattoRMM handle UI or API-triggered workflows with failure trapping. + - Idempotent & WhatIf support - uses ShouldProcess/SupportsShouldProcess to protect installs. + - Headless Offboard - runs every offboarding task serially just like "Select All" in the UI. - Throughout, secrets are never written to logs or console, and all operations produce - clear success/failure messages via Write-LogHybrid. + Throughout, secrets are never written to logs or console, and all operations produce clear success/failure messages via Write-LogHybrid. .PARAMETER UseWebhook @@ -150,6 +151,7 @@ # Runs the off-boarding tasks in sequence without launching the UI. #> +#endregion Documentation #region Safely bypass Restricted Execution Policy # ─── Safely bypass Restricted Execution Policy ─── if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage' -or @@ -183,6 +185,7 @@ $ConfirmPreference = 'None' SupportsShouldProcess=$true, ConfirmImpact= 'Medium' )] + #region Parameter Definitions param( # ───────────────────────────────────────────────────────── # Toolkit-only mode @@ -221,6 +224,7 @@ $ConfirmPreference = 'None' [Parameter(ParameterSetName='DattoInstall')][switch] $InstallRMM, [Parameter(ParameterSetName='DattoInstall')][switch] $SaveCopy ) + #endregion Parameter Definitions #region global variables @@ -1159,7 +1163,9 @@ $jsContent #endregion UIHtml - #region Handler Stubs + + #region Handler Stubs + #region HTTP responder helpers function Respond-Text { param($Context, $Text) @@ -1189,7 +1195,7 @@ $jsContent $Context.Response.OutputStream.Close() } - function Respond-JSON { +function Respond-JSON { param($Context, $Object) if (-not $Context -or -not $Context.Response) { return @@ -1201,8 +1207,10 @@ $jsContent $Context.Response.OutputStream.Write($bytes,0,$bytes.Length) $Context.Response.OutputStream.Close() } + #endregion HTTP responder helpers - function Handle-FetchSites { + #region Datto handlers + function Handle-FetchSites { param($Context) try { @@ -1232,6 +1240,9 @@ $jsContent } } + #endregion Datto handlers + + #region Onboarding handlers # On-boarding handlers function Handle-SetSVSPowerPlan { param($Context) @@ -1301,8 +1312,10 @@ $jsContent } -function Handle-InstallDattoRMM { - param($Context) + #endregion Onboarding handlers + + function Handle-InstallDattoRMM { + param($Context) try { if ($Context.Request.HttpMethod -ne 'POST') { @@ -1336,6 +1349,9 @@ function Handle-InstallDattoRMM { } } +#endregion Datto handlers + + #region App handlers function Handle-InstallChrome { param($Context) try { winget install --id=Google.Chrome --silent --accept-package-agreements --accept-source-agreements @@ -1358,8 +1374,11 @@ function Handle-InstallAcrobat { param($Context) } } - #Offboarding Handlers - function Handle-UninstallCyberQP { + #endregion App handlers + + #region Offboarding handlers + +function Handle-UninstallCyberQP { param($Context) try { @@ -1455,6 +1474,7 @@ function Handle-CleanupSVSMSP { } } + #endregion Offboarding handlers #endregion Handler Stubs