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,
# ─────────────────────────────────────────────────────────
# 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(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