Update StackMonkey.ps1

This commit is contained in:
2025-06-29 03:08:44 -04:00
parent 8d9419369d
commit bbd74603a1

View File

@@ -99,14 +99,25 @@
[Parameter(Mandatory,ParameterSetName='Toolkit')][switch]$SilentInstall, [Parameter(Mandatory,ParameterSetName='Toolkit')][switch]$SilentInstall,
# ───────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────
# Datto headless mode # Datto headless mode
# Both Datto sets share the webhook password
[Parameter(Mandatory,ParameterSetName='DattoFetch'),
Parameter(Mandatory,ParameterSetName='DattoInstall')][string]$N8nPassword,
# ─────────────────────────────────────────────────────────
# Fetchonly 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(Mandatory,ParameterSetName='Datto')][string] $N8nPassword,
[Parameter(ParameterSetName='Datto')][switch] $FetchSitesOnly,
[Parameter(ParameterSetName='Datto')][string] $OutputFile = 'datto_sites.csv', # ─────────────────────────────────────────────────────────
[Parameter(Mandatory,ParameterSetName='Datto')][string] $SiteUID, # Install set: target site must be provided
[Parameter(Mandatory,ParameterSetName='Datto')][string] $SiteName, [Parameter(Mandatory,ParameterSetName='DattoInstall')][string] $SiteUID,
[Parameter(ParameterSetName='Datto')][switch] $PushSiteVars, [Parameter(Mandatory,ParameterSetName='DattoInstall')][string] $SiteName,
[Parameter(ParameterSetName='Datto')][switch] $InstallRMM, [Parameter(ParameterSetName='DattoInstall')][switch] $PushSiteVars,
[Parameter(ParameterSetName='Datto')][switch] $SaveCopy [Parameter(ParameterSetName='DattoInstall')][switch] $InstallRMM,
[Parameter(ParameterSetName='DattoInstall')][switch] $SaveCopy
) )
#region — guarantee NuGet provider is present without prompting #region — guarantee NuGet provider is present without prompting
@@ -308,26 +319,18 @@ try{
# 2) If user only wants the site list, do that and exit # 2) If user only wants the site list, do that and exit
# ─────────────────────────────────────────────────────────── # ───────────────────────────────────────────────────────────
if ($FetchSitesOnly) { 'DattoFetch' {
Write-LogHybrid "Fetching site list only…" Info DattoAuth Write-LogHybrid "Fetching site list only…" Info DattoAuth
try { $sites = Get-DattoRmmSites -Password $N8nPassword
$siteList = Get-DattoRmmSites -Password $N8nPassword
}
catch {
Write-LogHybrid "Failed to fetch sites: $($_.Exception.Message)" Error DattoAuth
throw
}
# Export based on extension
$ext = [IO.Path]::GetExtension($OutputFile).ToLower() $ext = [IO.Path]::GetExtension($OutputFile).ToLower()
if ($ext -eq '.json') { if ($ext -eq '.json') {
$siteList | ConvertTo-Json -Depth 3 | Out-File -FilePath $OutputFile -Encoding UTF8 $sites | ConvertTo-Json -Depth 3 | Out-File -FilePath $OutputFile -Encoding UTF8
} } else {
else { $sites | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8
$siteList | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8
} }
Write-LogHybrid "Wrote $($siteList.Count) sites to $OutputFile" Success DattoAuth Write-LogHybrid "Wrote $($sites.Count) sites to $OutputFile" Success DattoAuth
return return
} }
@@ -337,8 +340,9 @@ try{
# 3) Invoke the existing Install-DattoRMM cmdlet # 3) Invoke the existing Install-DattoRMM cmdlet
# ──────────────────────────────────────────── # ────────────────────────────────────────────
'DattoInstall' {
Write-LogHybrid "Headless DattoRMM deploy" Info DattoAuth
if ($PSCmdlet.ShouldProcess("Datto site '$SiteName'", "Headless install")) { if ($PSCmdlet.ShouldProcess("Datto site '$SiteName'", "Headless install")) {
Install-DattoRMM ` Install-DattoRMM `
-ApiUrl $Global:ApiUrl ` -ApiUrl $Global:ApiUrl `
-ApiKey $Global:ApiKey ` -ApiKey $Global:ApiKey `
@@ -351,6 +355,7 @@ try{
} }
return return
} }
} }
#endregion ScriptMonkey run silently Entrypoint #endregion ScriptMonkey run silently Entrypoint