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',
# ───────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────
@@ -1367,20 +1367,27 @@ $script
# 2) If user only wants the site list, do that and exit # 2) If user only wants the site list, do that and exit
# ─────────────────────────────────────────────────────────── # ───────────────────────────────────────────────────────────
'DattoFetch' { 'DattoFetch' {
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
$ext = [IO.Path]::GetExtension($OutputFile).ToLower() if ($SaveSitesOnly) {
if ($ext -eq '.json') { # If SaveSitesOnly is true, save the output to a file
$sites | ConvertTo-Json -Depth 3 | Out-File -FilePath $OutputFile -Encoding UTF8 $ext = [IO.Path]::GetExtension($OutputFile).ToLower()
} else { if ($ext -eq '.json') {
$sites | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8 $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 # 3) Invoke the existing Install-DattoRMM cmdlet