diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index b73ef0c..9e2904c 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -123,7 +123,7 @@ # ───────────────────────────────────────────────────────── # Fetch only set write sites and exit - [Parameter(ParameterSetName='DattoFetch')][switch] $FetchSitesOnly, + [Parameter(ParameterSetName='DattoFetch')][switch] $SaveSitesOnly [Parameter(ParameterSetName='DattoFetch')][string] $OutputFile = 'datto_sites.csv', # ───────────────────────────────────────────────────────── @@ -1367,20 +1367,27 @@ $script # 2) If user only wants the site list, do that and exit # ─────────────────────────────────────────────────────────── - 'DattoFetch' { - Write-LogHybrid "Fetching site list only…" Info DattoAuth - $sites = Get-DattoRmmSites -Password $N8nPassword + 'DattoFetch' { + Write-LogHybrid "Fetching site list only…" Info DattoAuth + $sites = Get-DattoRmmSites -Password $N8nPassword - $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 + if ($SaveSitesOnly) { + # If SaveSitesOnly is true, save the output to a file + $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 + } else { + # If SaveSitesOnly is not true, just fetch sites (for UI purposes or silent mode without saving) + Write-LogHybrid "Sites fetched successfully, but not saved." Success DattoAuth + } + return } - Write-LogHybrid "Wrote $($sites.Count) sites to $OutputFile" Success DattoAuth - return - } # ──────────────────────────────────────────── # 3) Invoke the existing Install-DattoRMM cmdlet