Update samy.ps1
This commit is contained in:
37
samy.ps1
37
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 = '<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()]
|
||||
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'
|
||||
-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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user