From 7870c1efd37d2470208862a25200130881bc31e7 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Mon, 12 Jan 2026 12:40:40 -0500 Subject: [PATCH] Update samy.ps1 --- samy.ps1 | 73 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/samy.ps1 b/samy.ps1 index f8f8206..dc32c40 100644 --- a/samy.ps1 +++ b/samy.ps1 @@ -1914,16 +1914,14 @@ function Install-DattoRMM { function Get-TaskHandlerName { param([object]$Task) - # Preferred explicit properties (if your JSON provides them) foreach ($p in @('HandlerFn','Handler','Fn')) { if ($Task.PSObject.Properties.Name -contains $p) { - $v = [string]$Task.$p + $v = ([string]$Task.$p).Trim().TrimStart('/') if (-not [string]::IsNullOrWhiteSpace($v)) { return $v } } } - # Fallback convention: Name="InstallChrome" -> Invoke-InstallChrome - $n = [string]$Task.Name + $n = ([string]$Task.Name).Trim().TrimStart('/') if (-not [string]::IsNullOrWhiteSpace($n)) { return "Invoke-$n" } return $null @@ -2078,45 +2076,52 @@ function Install-DattoRMM { } + 'Offboard' { + Write-LogHybrid "Headless offboarding requested" Info OffBoard -LogToEvent + # Ne garde que les tâches réellement exécutables + $offboardTasks = $Global:SamyTasks | Where-Object { + $_.Page -eq 'offboard' -and -not [string]::IsNullOrWhiteSpace([string]$_.Name) + } - 'Offboard' { - Write-LogHybrid "Headless offboarding requested" Info OffBoard -LogToEvent - $offboardTasks = $Global:SamyTasks | Where-Object Page -EQ 'offboard' - if (-not $offboardTasks) { - Write-LogHybrid "No offboard tasks configured" Warning OffBoard -LogToEvent - return - } + if (-not $offboardTasks) { + Write-LogHybrid "No offboard tasks configured (or none with a Name)." Warning OffBoard -LogToEvent + return + } - if (-not $PSCmdlet.ShouldProcess("Full off-boarding flow", "Execute every offboard task")) { - return - } + if (-not $PSCmdlet.ShouldProcess("Full off-boarding flow", "Execute every offboard task")) { + return + } foreach ($task in $offboardTasks) { - try { - Write-LogHybrid "Running offboard task: $($task.Label)" Info OffBoard -LogToEvent + try { + Write-LogHybrid "Running offboard task: $($task.Label)" Info OffBoard -LogToEvent - $fn = Get-TaskHandlerName -Task $task - if ([string]::IsNullOrWhiteSpace($fn)) { - Write-LogHybrid "Offboard task is missing a handler (Id=$($task.Id) Label='$($task.Label)')" Error OffBoard -LogToEvent - continue + $fn = Get-TaskHandlerName -Task $task + if ([string]::IsNullOrWhiteSpace($fn)) { + Write-LogHybrid "Skipping task with missing handler (Id=$($task.Id) Name='$($task.Name)' Label='$($task.Label)')" Error OffBoard -LogToEvent + 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 + } } - - $cmd = Get-Command -Name $fn -ErrorAction SilentlyContinue - if (-not $cmd) { - Write-LogHybrid "Missing handler $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 } } - catch { - Write-LogHybrid "Offboard task $($task.Label) failed: $($_.Exception.Message)" Error OffBoard -LogToEvent - } + + Write-LogHybrid "Headless offboarding completed" Success OffBoard -LogToEvent + return }