From bbd74603a175c1cded0d7f28241ac7ccdd169e58 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sun, 29 Jun 2025 03:08:44 -0400 Subject: [PATCH] Update StackMonkey.ps1 --- StackMonkey.ps1 | 85 ++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index e54cb0d..08a83cd 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -99,14 +99,25 @@ [Parameter(Mandatory,ParameterSetName='Toolkit')][switch]$SilentInstall, # ───────────────────────────────────────────────────────── # Datto headless mode + + # Both Datto sets share the webhook password + [Parameter(Mandatory,ParameterSetName='DattoFetch'), + Parameter(Mandatory,ParameterSetName='DattoInstall')][string]$N8nPassword, + + # ───────────────────────────────────────────────────────── + # Fetch‐only set: write sites and exit + [Parameter(ParameterSetName='DattoFetch')][switch] $FetchSitesOnly, + [Parameter(ParameterSetName='DattoFetch')][string] $OutputFile = 'datto_sites.csv', + [Parameter(Mandatory,ParameterSetName='Datto')][string] $N8nPassword, - [Parameter(ParameterSetName='Datto')][switch] $FetchSitesOnly, - [Parameter(ParameterSetName='Datto')][string] $OutputFile = 'datto_sites.csv', - [Parameter(Mandatory,ParameterSetName='Datto')][string] $SiteUID, - [Parameter(Mandatory,ParameterSetName='Datto')][string] $SiteName, - [Parameter(ParameterSetName='Datto')][switch] $PushSiteVars, - [Parameter(ParameterSetName='Datto')][switch] $InstallRMM, - [Parameter(ParameterSetName='Datto')][switch] $SaveCopy + + # ───────────────────────────────────────────────────────── + # Install set: target site must be provided + [Parameter(Mandatory,ParameterSetName='DattoInstall')][string] $SiteUID, + [Parameter(Mandatory,ParameterSetName='DattoInstall')][string] $SiteName, + [Parameter(ParameterSetName='DattoInstall')][switch] $PushSiteVars, + [Parameter(ParameterSetName='DattoInstall')][switch] $InstallRMM, + [Parameter(ParameterSetName='DattoInstall')][switch] $SaveCopy ) #region — guarantee NuGet provider is present without prompting @@ -308,50 +319,44 @@ try{ # 2) If user only wants the site list, do that and exit # ─────────────────────────────────────────────────────────── - if ($FetchSitesOnly) { - Write-LogHybrid "Fetching site list only…" Info DattoAuth - try { - $siteList = Get-DattoRmmSites -Password $N8nPassword - } - catch { - Write-LogHybrid "Failed to fetch sites: $($_.Exception.Message)" Error DattoAuth - throw - } + 'DattoFetch' { + Write-LogHybrid "Fetching site list only…" Info DattoAuth + $sites = Get-DattoRmmSites -Password $N8nPassword - # Export based on extension - $ext = [IO.Path]::GetExtension($OutputFile).ToLower() - if ($ext -eq '.json') { - $siteList | ConvertTo-Json -Depth 3 | Out-File -FilePath $OutputFile -Encoding UTF8 - } - else { - $siteList | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8 - } - - Write-LogHybrid "Wrote $($siteList.Count) sites to $OutputFile" Success DattoAuth - return + $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 # ──────────────────────────────────────────── - 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 - } + '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 - } + + } } #endregion ScriptMonkey run silently Entrypoint