Forum Discussion
Bret_Whitcombe
Dec 05, 2023Copper Contributor
Custom Printer Deployment
Hi everyone, great to be here. I will try to explain this in the best way I can, in hope that someone can help me. I have been tasked to deploy Lexmark Print & Hold to 240 endpoints. So far I hav...
LainRobertson
Dec 05, 2023Silver Contributor
Hi, Bret.
I can't test this script out but one observation is that your various calls to Get-PrinterPort (beginning line 74) do not include "-ErrorAction:Stop" meaning an exception will not be thrown even if the port is not found - assuming your system has $ErrorActionPreference as Continue (the default value).
This means your subsequent Add-PrinterPort would not be being called.
Here's a simple one-liner to demonstrate the incorrect flagging of "success":
Example
try { Get-PrinterPort -Name "LPT2"; "Success"; } catch { "Failure" }
Output
And here's the expected one-liner and behaviour:
Example
try { Get-PrinterPort -Name "LPT2" -ErrorAction:Stop; "Success"; } catch { "Failure" }
Output
Cheers,
Lain