Update samy.ps1
This commit is contained in:
207
samy.ps1
207
samy.ps1
@@ -2019,50 +2019,39 @@ function Install-DattoRMM {
|
|||||||
|
|
||||||
#region EntryPoint: Define Invoke-ScriptAutomationMonkey
|
#region EntryPoint: Define Invoke-ScriptAutomationMonkey
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────
|
|
||||||
# 3) MAIN LOGIC (Toolkit vs DattoFetch vs DattoInstall vs UI)
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
switch ($PSCmdlet.ParameterSetName) {
|
switch ($PSCmdlet.ParameterSetName) {
|
||||||
'Toolkit' {
|
|
||||||
Write-LogHybrid "Toolkit-only mode" Info Startup -LogToEvent
|
|
||||||
Install-SVSMSP -InstallToolkit
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
'Cleanup' {
|
'Toolkit' {
|
||||||
Write-LogHybrid "Running Toolkit cleanup mode" Info Startup -LogToEvent
|
Write-LogHybrid "Toolkit-only mode" Info Startup -LogToEvent
|
||||||
Install-SVSMSP -Cleanup
|
Install-SVSMSP -InstallToolkit
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
# ───────────────────────────────────────────────────────────
|
'Cleanup' {
|
||||||
# 2) If user only wants the site list, do that and exit
|
Write-LogHybrid "Running Toolkit cleanup mode" Info Startup -LogToEvent
|
||||||
# ───────────────────────────────────────────────────────────
|
Install-SVSMSP -Cleanup
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
'DattoFetch' {
|
'DattoFetch' {
|
||||||
Write-LogHybrid "Fetching site list only…" Info DattoAuth -LogToEvent
|
Write-LogHybrid "Fetching site list only…" Info DattoAuth -LogToEvent
|
||||||
$sites = Install-DattoRMM `
|
$sites = Install-DattoRMM `
|
||||||
-UseWebhook `
|
-UseWebhook `
|
||||||
-WebhookPassword $WebhookPassword `
|
-WebhookPassword $WebhookPassword `
|
||||||
-FetchSites `
|
-FetchSites `
|
||||||
-SaveSitesList:$SaveSitesList `
|
-SaveSitesList:$SaveSitesList `
|
||||||
-OutputFile $OutputFile
|
-OutputFile $OutputFile
|
||||||
|
|
||||||
Write-LogHybrid "Done." Success DattoAuth -LogToEvent
|
Write-LogHybrid "Done." Success DattoAuth -LogToEvent
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
'DattoInstall' {
|
||||||
|
Write-LogHybrid "Headless DattoRMM deploy" Info DattoAuth -LogToEvent
|
||||||
|
|
||||||
# ────────────────────────────────────────────
|
if ($PSCmdlet.ShouldProcess("Datto site '$SiteName'", "Headless install")) {
|
||||||
# 3) Invoke the existing Install-DattoRMM cmdlet
|
Install-DattoRMM `
|
||||||
# ────────────────────────────────────────────
|
|
||||||
|
|
||||||
'DattoInstall' {
|
|
||||||
Write-LogHybrid "Headless DattoRMM deploy" Info DattoAuth -LogToEvent
|
|
||||||
|
|
||||||
if ($PSCmdlet.ShouldProcess("Datto site '$SiteName'", "Headless install")) {
|
|
||||||
Install-DattoRMM `
|
|
||||||
-UseWebhook `
|
-UseWebhook `
|
||||||
-WebhookPassword $WebhookPassword `
|
-WebhookPassword $WebhookPassword `
|
||||||
-SiteUID $SiteUID `
|
-SiteUID $SiteUID `
|
||||||
@@ -2070,103 +2059,95 @@ function Install-DattoRMM {
|
|||||||
-PushSiteVars:$PushSiteVars `
|
-PushSiteVars:$PushSiteVars `
|
||||||
-InstallRMM:$InstallRMM `
|
-InstallRMM:$InstallRMM `
|
||||||
-SaveCopy:$SaveCopy
|
-SaveCopy:$SaveCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
}
|
'Offboard' {
|
||||||
|
|
||||||
'Offboard' {
|
|
||||||
Write-LogHybrid "Headless offboarding requested" Info OffBoard -LogToEvent
|
Write-LogHybrid "Headless offboarding requested" Info OffBoard -LogToEvent
|
||||||
|
|
||||||
# Ne garde que les tâches réellement exécutables
|
|
||||||
$offboardTasks = $Global:SamyTasks | Where-Object {
|
$offboardTasks = $Global:SamyTasks | Where-Object {
|
||||||
$_.Page -eq 'offboard' -and -not [string]::IsNullOrWhiteSpace([string]$_.Name)
|
$_.Page -eq 'offboard' -and -not [string]::IsNullOrWhiteSpace([string]$_.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $offboardTasks) {
|
if (-not $offboardTasks) {
|
||||||
Write-LogHybrid "No offboard tasks configured (or none with a Name)." Warning OffBoard -LogToEvent
|
Write-LogHybrid "No offboard tasks configured (or none with a Name)." Warning OffBoard -LogToEvent
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $PSCmdlet.ShouldProcess("Full off-boarding flow", "Execute every offboard task")) {
|
if (-not $PSCmdlet.ShouldProcess("Full off-boarding flow", "Execute every offboard task")) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($task in $offboardTasks) {
|
foreach ($task in $offboardTasks) {
|
||||||
try {
|
try {
|
||||||
Write-LogHybrid "Running offboard task: $($task.Label)" Info OffBoard -LogToEvent
|
Write-LogHybrid "Running offboard task: $($task.Label)" Info OffBoard -LogToEvent
|
||||||
|
|
||||||
$fn = Get-TaskHandlerName -Task $task
|
$fn = Get-TaskHandlerName -Task $task
|
||||||
if ([string]::IsNullOrWhiteSpace($fn)) {
|
if ([string]::IsNullOrWhiteSpace($fn)) {
|
||||||
Write-LogHybrid "Skipping task with missing handler (Id=$($task.Id) Name='$($task.Name)' Label='$($task.Label)')" Error OffBoard -LogToEvent
|
Write-LogHybrid "Skipping task with missing handler (Id=$($task.Id) Name='$($task.Name)' Label='$($task.Label)')" Error OffBoard -LogToEvent
|
||||||
continue
|
continue
|
||||||
}
|
|
||||||
|
|
||||||
$cmd = Get-Command -Name $fn -ErrorAction SilentlyContinue
|
|
||||||
if (-not $cmd) {
|
|
||||||
Write-LogHybrid "Skipping task: handler not found '$fn' (task '$($task.Label)')" Error OffBoard -LogToEvent
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($cmd.Parameters.ContainsKey('Context')) {
|
|
||||||
& $fn -Context $null
|
|
||||||
} else {
|
|
||||||
& $fn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-LogHybrid "Offboard task '$($task.Label)' failed: $($_.Exception.Message)" Error OffBoard -LogToEvent
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-LogHybrid "Headless offboarding completed" Success OffBoard -LogToEvent
|
$cmd = Get-Command -Name $fn -ErrorAction SilentlyContinue
|
||||||
return
|
if (-not $cmd) {
|
||||||
}
|
Write-LogHybrid "Skipping task: handler not found '$fn' (task '$($task.Label)')" Error OffBoard -LogToEvent
|
||||||
|
continue
|
||||||
|
|
||||||
Write-LogHybrid "Headless offboarding completed" Success OffBoard -LogToEvent
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
'UI' {
|
|
||||||
$url = "http://localhost:$Port/"
|
|
||||||
Write-LogHybrid "Starting ScriptAutomationMonkey UI on $url" Info Startup
|
|
||||||
|
|
||||||
# Resolve Edge path explicitly (x86 first, then 64-bit, then PATH)
|
|
||||||
$edgeCandidates = @(
|
|
||||||
"${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe",
|
|
||||||
"$env:ProgramFiles\Microsoft\Edge\Application\msedge.exe"
|
|
||||||
)
|
|
||||||
$edgePath = $edgeCandidates | Where-Object { $_ -and (Test-Path $_) } | Select-Object -First 1
|
|
||||||
if (-not $edgePath) {
|
|
||||||
$cmd = Get-Command -Name 'msedge.exe' -ErrorAction SilentlyContinue
|
|
||||||
if ($cmd) { $edgePath = $cmd.Path }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Launch Edge (app mode) in a background job so Start-Server can block
|
if ($cmd.Parameters.ContainsKey('Context')) {
|
||||||
Start-Job -Name 'OpenScriptAutomationMonkeyUI' -ScriptBlock {
|
& $fn -Context $null
|
||||||
param([string]$u, [string]$edge)
|
} else {
|
||||||
Start-Sleep -Milliseconds 400
|
& $fn
|
||||||
try {
|
}
|
||||||
if ($edge -and (Test-Path $edge)) {
|
}
|
||||||
Start-Process -FilePath $edge -ArgumentList @('--new-window', "--app=$u")
|
catch {
|
||||||
} else {
|
Write-LogHybrid "Offboard task '$($task.Label)' failed: $($_.Exception.Message)" Error OffBoard -LogToEvent
|
||||||
Start-Process -FilePath $u # fallback to default browser
|
|
||||||
}
|
|
||||||
} catch { }
|
|
||||||
} -ArgumentList $url, $edgePath | Out-Null
|
|
||||||
|
|
||||||
# Now start the blocking listener loop
|
|
||||||
Start-Server
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endregion EntryPoint: Define Invoke-ScriptAutomationMonkey
|
|
||||||
|
Write-LogHybrid "Headless offboarding completed" Success OffBoard -LogToEvent
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
'UI' {
|
||||||
|
$url = "http://localhost:$Port/"
|
||||||
|
Write-LogHybrid "Starting ScriptAutomationMonkey UI on $url" Info Startup
|
||||||
|
|
||||||
|
$edgeCandidates = @(
|
||||||
|
"${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe",
|
||||||
|
"$env:ProgramFiles\Microsoft\Edge\Application\msedge.exe"
|
||||||
|
)
|
||||||
|
$edgePath = $edgeCandidates | Where-Object { $_ -and (Test-Path $_) } | Select-Object -First 1
|
||||||
|
if (-not $edgePath) {
|
||||||
|
$cmd = Get-Command -Name 'msedge.exe' -ErrorAction SilentlyContinue
|
||||||
|
if ($cmd) { $edgePath = $cmd.Path }
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Job -Name 'OpenScriptAutomationMonkeyUI' -ScriptBlock {
|
||||||
|
param([string]$u, [string]$edge)
|
||||||
|
Start-Sleep -Milliseconds 400
|
||||||
|
try {
|
||||||
|
if ($edge -and (Test-Path $edge)) {
|
||||||
|
Start-Process -FilePath $edge -ArgumentList @('--new-window', "--app=$u")
|
||||||
|
} else {
|
||||||
|
Start-Process -FilePath $u
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
} -ArgumentList $url, $edgePath | Out-Null
|
||||||
|
|
||||||
|
Start-Server
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
default {
|
||||||
|
Write-LogHybrid "Unknown ParameterSetName '$($PSCmdlet.ParameterSetName)'" Error Startup -LogToEvent
|
||||||
|
throw "Unknown mode."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion EntryPoint: Define Invoke-ScriptAutomationMonkey
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user