added more #regions

This commit is contained in:
2025-11-28 20:11:40 -05:00
parent ae5bcb677c
commit 2781493231

View File

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