added -savesiteonly

This commit is contained in:
2025-06-29 23:54:15 -04:00
parent 820140655e
commit 27ebad5a78

View File

@@ -123,7 +123,7 @@
# ───────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────
# Fetch only set write sites and exit # 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', [Parameter(ParameterSetName='DattoFetch')][string] $OutputFile = 'datto_sites.csv',
# ───────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────
@@ -1371,6 +1371,8 @@ $script
Write-LogHybrid "Fetching site list only…" Info DattoAuth Write-LogHybrid "Fetching site list only…" Info DattoAuth
$sites = Get-DattoRmmSites -Password $N8nPassword $sites = Get-DattoRmmSites -Password $N8nPassword
if ($SaveSitesOnly) {
# If SaveSitesOnly is true, save the output to a file
$ext = [IO.Path]::GetExtension($OutputFile).ToLower() $ext = [IO.Path]::GetExtension($OutputFile).ToLower()
if ($ext -eq '.json') { if ($ext -eq '.json') {
$sites | ConvertTo-Json -Depth 3 | Out-File -FilePath $OutputFile -Encoding UTF8 $sites | ConvertTo-Json -Depth 3 | Out-File -FilePath $OutputFile -Encoding UTF8
@@ -1379,9 +1381,14 @@ $script
} }
Write-LogHybrid "Wrote $($sites.Count) sites to $OutputFile" Success DattoAuth 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 return
} }
# ──────────────────────────────────────────── # ────────────────────────────────────────────
# 3) Invoke the existing Install-DattoRMM cmdlet # 3) Invoke the existing Install-DattoRMM cmdlet
# ──────────────────────────────────────────── # ────────────────────────────────────────────