Update StackMonkey.ps1

This commit is contained in:
2025-06-25 00:09:17 -04:00
parent d4482a10a4
commit bcdecbdb45

View File

@@ -63,9 +63,15 @@
#> #>
#region ScriptMonkey run silently Entrypoint #region ScriptMonkey run silently Entrypoint
[CmdletBinding(DefaultParameterSetName='UI',
SupportsShouldProcess = $true, # ─────────────────────────────────────────────────────────────────────────
ConfirmImpact = 'Medium' # 1) ENTRYPOINT + PARAMETER DECLARATION
# ─────────────────────────────────────────────────────────────────────────
[CmdletBinding(
DefaultParameterSetName='UI',
SupportsShouldProcess=$true,
ConfirmImpact= 'Medium'
)] )]
param( param(
# ───────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────
@@ -81,18 +87,21 @@
[Parameter(ParameterSetName='Datto')][switch] $SaveCopy [Parameter(ParameterSetName='Datto')][switch] $SaveCopy
) )
# Listening port for HTTP UI # ─────────────────────────────────────────────────────────────────────────
$Port = 8082 # 2) GLOBAL SETTINGS & HELPERS
# ─────────────────────────────────────────────────────────────────────────
# Configurable endpoints # Listening port for HTTP UI
$Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit' $Port = 8082
# Configurable endpoints
$Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit'
#region Get-DattoApiCredentials #region Get-DattoApiCredentials
function Get-DattoApiCredentials { function Get-DattoApiCredentials {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[Parameter(Mandatory)] [Parameter(Mandatory)][string]$Password
[string]$Password
) )
$headers = @{ "SVSMSPKit" = $Password } $headers = @{ "SVSMSPKit" = $Password }
try { try {
@@ -110,9 +119,9 @@ function Get-DattoApiCredentials {
return $null return $null
} }
} }
# ─────────────────────────────────────────────────────────────────────────
#endregion # 3) MAIN LOGIC (Toolkit vs Datto vs UI)
# ─────────────────────────────────────────────────────────────────────────
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'Toolkit' { 'Toolkit' {
@@ -126,17 +135,16 @@ function Get-DattoApiCredentials {
# ──────────────────────────────────────────── # ────────────────────────────────────────────
# 1) Fetch URL, Key & Secret from n8n webhook # 1) Fetch URL, Key & Secret from n8n webhook
# (this is your lines 415-424)
# ──────────────────────────────────────────── # ────────────────────────────────────────────
# 1) Fetch creds # 1) Fetch creds
$resp = Get-DattoApiCredentials -Password $N8nPassword $creds = Get-DattoApiCredentials -Password $N8nPassword
if (-not $resp) { throw "Could not fetch creds" } if (-not $creds) { throw "Could not fetch creds" }
# 2) Store in globals for everyone else # 2) Store in globals for everyone else
$Global:ApiUrl = $resp.ApiUrl $Global:ApiUrl = $creds.ApiUrl
$Global:ApiKey = $resp.ApiKey $Global:ApiKey = $creds.ApiKey
$Global:ApiSecretKey = $resp.ApiSecretKey $Global:ApiSecretKey = $creds.ApiSecretKey
Write-LogHelper "Fetched Datto API credentials from n8n" Success DattoAuth Write-LogHelper "Fetched Datto API credentials from n8n" Success DattoAuth
} }
@@ -149,7 +157,7 @@ function Get-DattoApiCredentials {
# 2) Invoke the existing Install-DattoRMM cmdlet # 2) Invoke the existing Install-DattoRMM cmdlet
# ──────────────────────────────────────────── # ────────────────────────────────────────────
if ($PSCmdlet.ShouldProcess("Datto site '$SiteName'", "Headless install")) {
Install-DattoRMM ` Install-DattoRMM `
-ApiUrl $Global:ApiUrl ` -ApiUrl $Global:ApiUrl `
@@ -160,14 +168,12 @@ function Get-DattoApiCredentials {
-PushSiteVars:$PushSiteVars ` -PushSiteVars:$PushSiteVars `
-InstallRMM:$InstallRMM ` -InstallRMM:$InstallRMM `
-SaveCopy:$SaveCopy -SaveCopy:$SaveCopy
}
return return
} }
#endregion ScriptMonkey run silently Entrypoint
# STACK = Scripted Tooling for Automated Client Kickoff # STACK = Scripted Tooling for Automated Client Kickoff