I have a relatively simple powershell script, basically check for existing printers, remove the ones that aren't approved, then add the ones I specified. The script is failing at the add-printer cmdlet only sometimes when I run it from startup folder for all users. Here's the error.
+ Add-Printer -ConnectionName $serverPath$printer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_Printer:ROOT/StandardCimv2/MSFT_Printer) [Add-Printer],
CimException
+ FullyQualifiedErrorId : HRESULT 0x80070057,Add-Printer
Add-Printer : One or more specified parameters for this operation has an invalid value.
I've tried printing out the $serverPath and $printer variables, both have valid values in them. The funny thing is, I start a powershell shell, run the same file, and no error whatsoever.
The script works like 50/50 of the time. I can't, for the life of me, get rid of the error.
$serverPath
is "\\FQDMN.dmn\"
and $printer
is "printer-name"
formats (with hyphen)
Help?
I echoed the variables to confirm they have valid values, switched on transcript for powershell at GPO level as well as use start-transcript cmdlet to record the errors for diagnostic. I used the same user account with clearing reg hive and profile folder in between tests, and sometimes the script runs, sometimes it throw error.