Fix printer mapping to strip underscore suffix from port name
Port names like 10.80.92.53_2 are now cleaned to 10.80.92.53 before sending to the API for printer lookup. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -926,9 +926,7 @@ function Get-DefaultPrinterFQDN {
|
|||||||
Write-Host " Port Name: $portName" -ForegroundColor Gray
|
Write-Host " Port Name: $portName" -ForegroundColor Gray
|
||||||
|
|
||||||
# Check if this is a network printer (not a local/virtual printer)
|
# Check if this is a network printer (not a local/virtual printer)
|
||||||
# Network printer ports are: IP addresses, FQDNs, or UNC paths
|
$localPorts = @('USB', 'LPT', 'COM', 'PORTPROMPT:', 'FILE:', 'NUL:', 'XPS', 'PDF', 'FOXIT', 'Microsoft')
|
||||||
# Skip local printer ports: USB*, LPT*, COM*, PORTPROMPT:, FILE:, NUL:, etc.
|
|
||||||
$localPorts = @('USB', 'LPT', 'COM', 'PORTPROMPT:', 'FILE:', 'NUL:', 'XPS', 'PDF')
|
|
||||||
$isLocalPrinter = $false
|
$isLocalPrinter = $false
|
||||||
|
|
||||||
foreach ($localPort in $localPorts) {
|
foreach ($localPort in $localPorts) {
|
||||||
@@ -943,9 +941,12 @@ function Get-DefaultPrinterFQDN {
|
|||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
# This appears to be a network printer (IP, FQDN, or UNC path)
|
# Strip anything after and including underscore (e.g., 10.80.92.53_2 -> 10.80.92.53)
|
||||||
|
$cleanPort = $portName -replace '_.*$', ''
|
||||||
|
|
||||||
Write-Host " [OK] Network printer detected - will send to database" -ForegroundColor Green
|
Write-Host " [OK] Network printer detected - will send to database" -ForegroundColor Green
|
||||||
return $portName
|
Write-Host " Clean port: $cleanPort" -ForegroundColor Gray
|
||||||
|
return $cleanPort
|
||||||
} else {
|
} else {
|
||||||
Write-Host " No default printer found or no port available" -ForegroundColor Yellow
|
Write-Host " No default printer found or no port available" -ForegroundColor Yellow
|
||||||
return $null
|
return $null
|
||||||
|
|||||||
Reference in New Issue
Block a user