最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

startup - Powershell script throws error 80070057 only sometimes - Stack Overflow

programmeradmin5浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论