I'm running a PowerShell script to add printers, using a FQDN like 'server' and a printer name 'printerName'. I join these into a printer path and then call the Add-Printer function. The weird part? Sometimes it works perfectly, but about 40% of the time I get the error: "One or more specified parameters for this operation has an invalid value." It's baffling because all my variables seem correct when I print them out, yet the error hits randomly. I even delayed the execution by 30 seconds after user login, but it doesn't help. The script seems to run fine when I trigger it manually. I've put it inside a do-while loop, but it doesn't repeat when the error occurs, which adds to the confusion. I'm really hoping someone can shed some light on this odd issue!
2 Answers
It sounds like there might be an issue with how the Join-Path functions when you're using leading backslashes. This could be causing your printer names not to resolve correctly. Instead, consider directly concatenating the server name and printer name without Join-Path. Just use something like this:
```
$path = "\$serverName$printerName"
```
Also, if you’re running into a terminating error, wrapping the Add-Printer command in a Try-Catch block may help catch the error without stopping the script entirely.
Sharing your code often helps diagnose issues faster. It's great you added your code in an edit! One thing to watch for is if your printer names have leading backslashes that could be messing up the Join-Path command.
If you consistently get errors at startup but not when you run it manually, it might also be a timing issue. Maybe the network isn’t fully ready to add the printer on startup? Try adding a brief pause or check if the network is accessible before the add command.
Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically