Update samy.ps1

This commit is contained in:
2025-12-05 12:56:26 -05:00
parent b8b943e030
commit ee0ff44251

View File

@@ -1690,33 +1690,53 @@ function Invoke-CleanupSVSMSP {
#region Printer handlers #region Printer handlers
function Get-SamyClientListFromServer { 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 = '<password>' }
-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()] [CmdletBinding()]
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory)]
[string]$Uri, [string]$Uri,
[Parameter(Mandatory = $true)] [Parameter(Mandatory)]
[string]$Password [string]$Password
) )
try { try {
Write-LogHybrid "Calling client list service at $Uri" Info Printers -LogToEvent Write-LogHybrid "Calling client list service at $Uri" Info Printers -LogToEvent
# Adjust this to match how your bananas.svstools.ca endpoint expects auth. $headers = @{
# Here I'm assuming JSON POST { "password": "..." }. SAMYPW = $Password
$body = @{ password = $Password } | ConvertTo-Json }
$resp = Invoke-RestMethod -Uri $Uri ` $resp = Invoke-RestMethod -Uri $Uri `
-Method Post ` -Method Post `
-Body $body ` -Headers $headers `
-ContentType 'application/json' -ContentType 'application/json' `
-ErrorAction Stop
if (-not $resp) { if (-not $resp) {
Write-LogHybrid "Client list service returned no data." Warning Printers -LogToEvent Write-LogHybrid "Client list service returned no data." Warning Printers -LogToEvent
return @() 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])) { if ($resp -is [System.Collections.IEnumerable] -and -not ($resp -is [string])) {
return @($resp) return @($resp)
} else { } else {
@@ -1730,6 +1750,7 @@ function Get-SamyClientListFromServer {
} }
function Invoke-GetPrinters { function Invoke-GetPrinters {
param($Context) param($Context)