added headless offboard
This commit is contained in:
70
samy.ps1
70
samy.ps1
@@ -68,6 +68,9 @@
|
|||||||
.PARAMETER SaveCopy
|
.PARAMETER SaveCopy
|
||||||
Switch to save a copy of the downloaded Datto RMM installer into C:\Temp.
|
Switch to save a copy of the downloaded Datto RMM installer into C:\Temp.
|
||||||
|
|
||||||
|
.PARAMETER Offboard
|
||||||
|
Switch that runs every off-boarding task sequentially (same behavior as checking "Select All" on the Off-Boarding tab) without launching the web UI.
|
||||||
|
|
||||||
.PARAMETER SiteUID
|
.PARAMETER SiteUID
|
||||||
The unique identifier of the Datto RMM site. Mandatory when performing install or variable-push.
|
The unique identifier of the Datto RMM site. Mandatory when performing install or variable-push.
|
||||||
|
|
||||||
@@ -141,6 +144,11 @@
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
& ([ScriptBlock]::Create((iwr 'sm.svstools.com').Content)) -Cleanup
|
& ([ScriptBlock]::Create((iwr 'sm.svstools.com').Content)) -Cleanup
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
& ([ScriptBlock]::Create((iwr 'samy.svstools.ca').Content)) -Offboard
|
||||||
|
|
||||||
|
# Runs the off-boarding tasks in sequence without launching the UI.
|
||||||
|
|
||||||
#>
|
#>
|
||||||
#region Safely bypass Restricted Execution Policy
|
#region Safely bypass Restricted Execution Policy
|
||||||
# ─── Safely bypass Restricted Execution Policy ───
|
# ─── Safely bypass Restricted Execution Policy ───
|
||||||
@@ -184,6 +192,9 @@ $ConfirmPreference = 'None'
|
|||||||
# remove Toolkit
|
# remove Toolkit
|
||||||
[Parameter(Mandatory,ParameterSetName='Cleanup')][switch]$Cleanup,
|
[Parameter(Mandatory,ParameterSetName='Cleanup')][switch]$Cleanup,
|
||||||
|
|
||||||
|
# headless offboarding
|
||||||
|
[Parameter(Mandatory,ParameterSetName='Offboard')][switch]$Offboard,
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────
|
# ─────────────────────────────────────────────────────────
|
||||||
# Datto headless mode
|
# Datto headless mode
|
||||||
|
|
||||||
@@ -1142,6 +1153,9 @@ $jsContent
|
|||||||
|
|
||||||
function Respond-Text {
|
function Respond-Text {
|
||||||
param($Context, $Text)
|
param($Context, $Text)
|
||||||
|
if (-not $Context -or -not $Context.Response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
$bytes = [Text.Encoding]::UTF8.GetBytes($Text)
|
$bytes = [Text.Encoding]::UTF8.GetBytes($Text)
|
||||||
$Context.Response.ContentType = 'text/plain'
|
$Context.Response.ContentType = 'text/plain'
|
||||||
$Context.Response.ContentLength64 = $bytes.Length
|
$Context.Response.ContentLength64 = $bytes.Length
|
||||||
@@ -1155,6 +1169,9 @@ $jsContent
|
|||||||
[Parameter(Mandatory = $true)][object] $Context,
|
[Parameter(Mandatory = $true)][object] $Context,
|
||||||
[Parameter(Mandatory = $true)][string] $Html
|
[Parameter(Mandatory = $true)][string] $Html
|
||||||
)
|
)
|
||||||
|
if (-not $Context -or -not $Context.Response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
$bytes = [Text.Encoding]::UTF8.GetBytes($Html)
|
$bytes = [Text.Encoding]::UTF8.GetBytes($Html)
|
||||||
$Context.Response.ContentType = 'text/html'
|
$Context.Response.ContentType = 'text/html'
|
||||||
$Context.Response.ContentLength64 = $bytes.Length
|
$Context.Response.ContentLength64 = $bytes.Length
|
||||||
@@ -1162,8 +1179,11 @@ $jsContent
|
|||||||
$Context.Response.OutputStream.Close()
|
$Context.Response.OutputStream.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
function Respond-JSON {
|
function Respond-JSON {
|
||||||
param($Context, $Object)
|
param($Context, $Object)
|
||||||
|
if (-not $Context -or -not $Context.Response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
$json = $Object | ConvertTo-Json -Depth 5
|
$json = $Object | ConvertTo-Json -Depth 5
|
||||||
$bytes = [Text.Encoding]::UTF8.GetBytes($json)
|
$bytes = [Text.Encoding]::UTF8.GetBytes($json)
|
||||||
$Context.Response.ContentType = 'application/json'
|
$Context.Response.ContentType = 'application/json'
|
||||||
@@ -1755,35 +1775,37 @@ function Install-DattoRMM {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<#
|
|
||||||
|
|
||||||
'UI' {
|
|
||||||
$url = "http://localhost:$Port/"
|
|
||||||
Write-LogHybrid "Starting ScriptAutomationMonkey UI on $url" Info Startup
|
|
||||||
|
|
||||||
# Open the UI in a separate PowerShell job so Start-Server can block safely.
|
|
||||||
try {
|
'Offboard' {
|
||||||
Start-Job -Name 'OpenScriptAutomationMonkeyUI' -ScriptBlock {
|
Write-LogHybrid "Headless offboarding requested" Info OffBoard -LogToEvent
|
||||||
param($u)
|
$offboardTasks = $Global:SamyTasks | Where-Object Page -EQ 'offboard'
|
||||||
Start-Sleep -Milliseconds 300
|
if (-not $offboardTasks) {
|
||||||
try {
|
Write-LogHybrid "No offboard tasks configured" Warning OffBoard -LogToEvent
|
||||||
if (Get-Command -Name 'msedge.exe' -ErrorAction SilentlyContinue) {
|
return
|
||||||
Start-Process -FilePath 'msedge.exe' -ArgumentList "--app=$u"
|
|
||||||
} else {
|
|
||||||
Start-Process -FilePath $u
|
|
||||||
}
|
|
||||||
} catch { }
|
|
||||||
} -ArgumentList $url | Out-Null
|
|
||||||
} catch {
|
|
||||||
Write-LogHybrid "Failed to schedule browser launch: $($_.Exception.Message)" Warning Startup -LogToEvent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Now start the blocking listener loop
|
if (-not $PSCmdlet.ShouldProcess("Full off-boarding flow", "Execute every offboard task")) {
|
||||||
Start-Server
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($task in $offboardTasks) {
|
||||||
|
try {
|
||||||
|
Write-LogHybrid "Running offboard task: $($task.Label)" Info OffBoard -LogToEvent
|
||||||
|
if (-not (Get-Command $task.HandlerFn -ErrorAction SilentlyContinue)) {
|
||||||
|
Write-LogHybrid "Missing handler $($task.HandlerFn)" Error OffBoard -LogToEvent
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
& $task.HandlerFn $null
|
||||||
|
} catch {
|
||||||
|
Write-LogHybrid "Offboard task $($task.Label) failed: $($_.Exception.Message)" Error OffBoard -LogToEvent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-LogHybrid "Headless offboarding complete" Success OffBoard -LogToEvent
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
#>
|
|
||||||
|
|
||||||
'UI' {
|
'UI' {
|
||||||
$url = "http://localhost:$Port/"
|
$url = "http://localhost:$Port/"
|
||||||
|
|||||||
Reference in New Issue
Block a user