Update samy.ps1
This commit is contained in:
53
samy.ps1
53
samy.ps1
@@ -1832,17 +1832,58 @@ function Invoke-InstallPrinters {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Write-LogHybrid "Received request to install $($printers.Count) printers (WHATIF mode)." Info Printers -LogToEvent
|
||||||
|
|
||||||
|
$successCount = 0
|
||||||
|
$failures = @()
|
||||||
|
|
||||||
foreach ($p in $printers) {
|
foreach ($p in $printers) {
|
||||||
# TODO: Replace this with your real install logic once ready
|
# Expecting fields from JSON:
|
||||||
$msg = "Requested install: ClientCode=$($p.ClientCode) ProfileName=$($p.ProfileName) DisplayName=$($p.DisplayName) Location=$($p.Location)"
|
# ClientCode = 'ABC'
|
||||||
Write-LogHybrid $msg Info Printers -LogToEvent
|
# ProfileName = 'FrontDesk'
|
||||||
|
# SetAsDefault = $true/$false (optional)
|
||||||
|
|
||||||
|
$clientCode = $p.ClientCode
|
||||||
|
$profileName = $p.ProfileName
|
||||||
|
$setDefault = $false
|
||||||
|
if ($p.PSObject.Properties.Name -contains 'SetAsDefault' -and $p.SetAsDefault) {
|
||||||
|
$setDefault = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $clientCode -or -not $profileName) {
|
||||||
|
$msg = "Skipping printer entry because ClientCode or ProfileName is missing."
|
||||||
|
Write-LogHybrid $msg Warning Printers -LogToEvent
|
||||||
|
$failures += $msg
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
$summary = "ClientCode=$clientCode ProfileName=$profileName SetAsDefault=$setDefault"
|
||||||
|
Write-LogHybrid "WHATIF: Installing printer ($summary)" Info Printers -LogToEvent
|
||||||
|
|
||||||
|
try {
|
||||||
|
# 🔐 SAFE PHASE: we call with -WhatIf so no real change happens
|
||||||
|
Invoke-SamyPrinterInstall `
|
||||||
|
-ClientCode $clientCode `
|
||||||
|
-ProfileName $profileName `
|
||||||
|
-SetAsDefault:$setDefault `
|
||||||
|
-WhatIf
|
||||||
|
|
||||||
|
$successCount++
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$errMsg = "Failed (WHATIF) to install printer ($summary): $($_.Exception.Message)"
|
||||||
|
Write-LogHybrid $errMsg Error Printers -LogToEvent
|
||||||
|
$failures += $errMsg
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = @{
|
$result = @{
|
||||||
Success = $true
|
SuccessCount = $successCount
|
||||||
Count = $printers.Count
|
FailureCount = $failures.Count
|
||||||
Message = "Printer install requests logged on the SAMY server."
|
Failures = $failures
|
||||||
|
Message = "Printer install (WHATIF) processed. Check SAMY logs for detail."
|
||||||
}
|
}
|
||||||
|
|
||||||
Send-JSON $Context $result
|
Send-JSON $Context $result
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user