Update samy.ps1
This commit is contained in:
27
samy.ps1
27
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,13 +2076,16 @@ function Install-DattoRMM {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
'Offboard' {
|
||||
Write-LogHybrid "Headless offboarding requested" Info OffBoard -LogToEvent
|
||||
$offboardTasks = $Global:SamyTasks | Where-Object Page -EQ 'offboard'
|
||||
|
||||
# Ne garde que les tâches réellement exécutables
|
||||
$offboardTasks = $Global:SamyTasks | Where-Object {
|
||||
$_.Page -eq 'offboard' -and -not [string]::IsNullOrWhiteSpace([string]$_.Name)
|
||||
}
|
||||
|
||||
if (-not $offboardTasks) {
|
||||
Write-LogHybrid "No offboard tasks configured" Warning OffBoard -LogToEvent
|
||||
Write-LogHybrid "No offboard tasks configured (or none with a Name)." Warning OffBoard -LogToEvent
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2098,13 +2099,13 @@ function Install-DattoRMM {
|
||||
|
||||
$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
|
||||
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 "Missing handler $fn (task '$($task.Label)')" Error OffBoard -LogToEvent
|
||||
Write-LogHybrid "Skipping task: handler not found '$fn' (task '$($task.Label)')" Error OffBoard -LogToEvent
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -2115,10 +2116,14 @@ function Install-DattoRMM {
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-LogHybrid "Offboard task $($task.Label) failed: $($_.Exception.Message)" Error OffBoard -LogToEvent
|
||||
Write-LogHybrid "Offboard task '$($task.Label)' failed: $($_.Exception.Message)" Error OffBoard -LogToEvent
|
||||
}
|
||||
}
|
||||
|
||||
Write-LogHybrid "Headless offboarding completed" Success OffBoard -LogToEvent
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Write-LogHybrid "Headless offboarding completed" Success OffBoard -LogToEvent
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user