Update StackMonkey.ps1
This commit is contained in:
244
StackMonkey.ps1
244
StackMonkey.ps1
@@ -135,128 +135,7 @@
|
||||
[Parameter(ParameterSetName='DattoInstall')][switch] $SaveCopy
|
||||
)
|
||||
|
||||
#region ScriptMonkey run silently Entrypoint
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# 3) MAIN LOGIC (Toolkit vs DattoFetch vs DattoInstall vs UI)
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'Toolkit' {
|
||||
Write-LogHybrid "Toolkit-only mode" Info Startup
|
||||
Install-SVSMSP -InstallToolkit
|
||||
return
|
||||
}
|
||||
|
||||
'Cleanup' {
|
||||
Write-LogHybrid "Running Toolkit cleanup mode" Info Startup
|
||||
Install-SVSMSP -Cleanup
|
||||
return
|
||||
}
|
||||
|
||||
# ───────────────────────────────────────────────────────────
|
||||
# 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
|
||||
|
||||
$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
|
||||
# ────────────────────────────────────────────
|
||||
|
||||
'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
|
||||
|
||||
}
|
||||
|
||||
'UI' {
|
||||
Write-LogHybrid "Launching UI" Info Startup
|
||||
Write-Host "Starting ScriptMonkey UI on http://localhost:$Port/" -ForegroundColor Cyan
|
||||
Start-Process "msedge.exe" -ArgumentList "--app=http://localhost:$Port"
|
||||
Start-Server # blocks until you click Exit
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
#endregion ScriptMonkey run silently Entrypoint
|
||||
|
||||
Write-Host "🛠️ SAMY - Script Automation Monkey (Yeah!)" -ForegroundColor Cyan
|
||||
Write-Host "ParameterSetName: $($PSCmdlet.ParameterSetName)" -ForegroundColor Yellow
|
||||
|
||||
#region — guarantee NuGet provider is present without prompting
|
||||
|
||||
# ─── Top of script ───
|
||||
Import-Module PackageManagement -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
Import-Module PowerShellGet -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
# ─── ensure TLS 1.2 + no prompts ───
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
$ConfirmPreference = 'None'
|
||||
|
||||
# check if NuGet exists (no output—assigned to $nuget)
|
||||
$nuget = Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue
|
||||
|
||||
if (-not $nuget) {
|
||||
# install it (again, assignment suppresses the table)
|
||||
Install-PackageProvider `
|
||||
-Name NuGet `
|
||||
-MinimumVersion 2.8.5.201 `
|
||||
-Force `
|
||||
-Confirm:$false
|
||||
|
||||
|
||||
# re-query just for version info
|
||||
$found = Get-PackageProvider -Name NuGet -ListAvailable
|
||||
Write-Host "Installed NuGet provider v$($found.Version)" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "NuGet provider already present (v$($found.Version))" -ForegroundColor DarkGray
|
||||
}
|
||||
|
||||
# now import it silently
|
||||
Import-PackageProvider -Name NuGet -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
# ensure trust PSGallery without its own output (so you don't get “untrusted repository” prompt
|
||||
$gallery = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue
|
||||
if ($gallery.InstallationPolicy -ne 'Trusted') {
|
||||
Set-PSRepository `
|
||||
-Name PSGallery `
|
||||
-InstallationPolicy Trusted `
|
||||
-ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
Write-Host "PSGallery marked as Trusted" -ForegroundColor Green
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region globalsetting
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# 2) GLOBAL SETTINGS & HELPERS
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
@@ -433,6 +312,127 @@
|
||||
}
|
||||
|
||||
|
||||
#endregion region globalsetting
|
||||
|
||||
#region ScriptMonkey run silently Entrypoint
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
# 3) MAIN LOGIC (Toolkit vs DattoFetch vs DattoInstall vs UI)
|
||||
# ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'Toolkit' {
|
||||
Write-LogHybrid "Toolkit-only mode" Info Startup
|
||||
Install-SVSMSP -InstallToolkit
|
||||
return
|
||||
}
|
||||
|
||||
'Cleanup' {
|
||||
Write-LogHybrid "Running Toolkit cleanup mode" Info Startup
|
||||
Install-SVSMSP -Cleanup
|
||||
return
|
||||
}
|
||||
|
||||
# ───────────────────────────────────────────────────────────
|
||||
# 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
|
||||
|
||||
$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
|
||||
# ────────────────────────────────────────────
|
||||
|
||||
'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
|
||||
|
||||
}
|
||||
|
||||
'UI' {
|
||||
Write-LogHybrid "Launching UI" Info Startup
|
||||
Write-Host "Starting ScriptMonkey UI on http://localhost:$Port/" -ForegroundColor Cyan
|
||||
Start-Process "msedge.exe" -ArgumentList "--app=http://localhost:$Port"
|
||||
Start-Server # blocks until you click Exit
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
#endregion ScriptMonkey run silently Entrypoint
|
||||
|
||||
Write-Host "🛠️ SAMY - Script Automation Monkey (Yeah!)" -ForegroundColor Cyan
|
||||
Write-Host "ParameterSetName: $($PSCmdlet.ParameterSetName)" -ForegroundColor Yellow
|
||||
|
||||
#region — guarantee NuGet provider is present without prompting
|
||||
|
||||
# ─── Top of script ───
|
||||
Import-Module PackageManagement -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
Import-Module PowerShellGet -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
# ─── ensure TLS 1.2 + no prompts ───
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
$ConfirmPreference = 'None'
|
||||
|
||||
# check if NuGet exists (no output—assigned to $nuget)
|
||||
$nuget = Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue
|
||||
|
||||
if (-not $nuget) {
|
||||
# install it (again, assignment suppresses the table)
|
||||
Install-PackageProvider `
|
||||
-Name NuGet `
|
||||
-MinimumVersion 2.8.5.201 `
|
||||
-Force `
|
||||
-Confirm:$false
|
||||
|
||||
|
||||
# re-query just for version info
|
||||
$found = Get-PackageProvider -Name NuGet -ListAvailable
|
||||
Write-Host "Installed NuGet provider v$($found.Version)" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "NuGet provider already present (v$($found.Version))" -ForegroundColor DarkGray
|
||||
}
|
||||
|
||||
# now import it silently
|
||||
Import-PackageProvider -Name NuGet -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
# ensure trust PSGallery without its own output (so you don't get “untrusted repository” prompt
|
||||
$gallery = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue
|
||||
if ($gallery.InstallationPolicy -ne 'Trusted') {
|
||||
Set-PSRepository `
|
||||
-Name PSGallery `
|
||||
-InstallationPolicy Trusted `
|
||||
-ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
Write-Host "PSGallery marked as Trusted" -ForegroundColor Green
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Config & Task Definitions
|
||||
|
||||
Reference in New Issue
Block a user