From ee0ff44251fc04016018204af373ba39bade97a9 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Fri, 5 Dec 2025 12:56:26 -0500 Subject: [PATCH] Update samy.ps1 --- samy.ps1 | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/samy.ps1 b/samy.ps1 index b666d74..34c6072 100644 --- a/samy.ps1 +++ b/samy.ps1 @@ -1690,33 +1690,53 @@ function Invoke-CleanupSVSMSP { #region Printer handlers function Get-SamyClientListFromServer { + <# + .SYNOPSIS + Queries the Node.js service for a list of clients/printers using a SAMYPW header. + + .DESCRIPTION + Calls your Node.js endpoint with: + + -Method Post + -Headers @{ SAMYPW = '' } + -ContentType 'application/json' + + and returns the JSON it sends back (normalized to an array). + + .PARAMETER Uri + The HTTP/HTTPS endpoint (e.g. https://bananas.svstools.ca/getprinters). + + .PARAMETER Password + Password/API key that will be sent as the SAMYPW header. + #> [CmdletBinding()] param( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory)] [string]$Uri, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory)] [string]$Password ) try { Write-LogHybrid "Calling client list service at $Uri" Info Printers -LogToEvent - # Adjust this to match how your bananas.svstools.ca endpoint expects auth. - # Here I'm assuming JSON POST { "password": "..." }. - $body = @{ password = $Password } | ConvertTo-Json + $headers = @{ + SAMYPW = $Password + } $resp = Invoke-RestMethod -Uri $Uri ` - -Method Post ` - -Body $body ` - -ContentType 'application/json' + -Method Post ` + -Headers $headers ` + -ContentType 'application/json' ` + -ErrorAction Stop if (-not $resp) { Write-LogHybrid "Client list service returned no data." Warning Printers -LogToEvent return @() } - # Normalize to an array + # Normalize to an array so callers can rely on it if ($resp -is [System.Collections.IEnumerable] -and -not ($resp -is [string])) { return @($resp) } else { @@ -1730,6 +1750,7 @@ function Get-SamyClientListFromServer { } + function Invoke-GetPrinters { param($Context)