创建打印机 Powershell

发布于 2024-10-27 21:44:53 字数 1416 浏览 0 评论 0原文

我在获取我正在编写的脚本来成功创建打印机时遇到了很大的困难。到目前为止,我已成功创建打印机端口,但在创建打印机时总是出错。

它从中获取信息的 CSV 文件如下所示:

PrinterName,PrinterPort,IPAddress,Location,Comment,PrintDriver,
Testprint1,Testport1,10.10.10.10,IT_Test,Test_1,HP LaserJet 4200 PCL 5e,

我收到的错误消息是这样的:

Exception calling "Put" with "0" argument(s): "Generic failure "
At C:\myversion.ps1:53 char:19
+ $objNewPrinter.Put <<<< () 
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

我正在使用的代码是这样的:

trap { $error[0].Exception | get-member } $objNewPrinter.Put()

Write-Host ("`tCreating " + $strPrinterName.Count + " Printer's`t") 
$objPrint = [WMICLASS]"\\timvista\ROOT\cimv2:Win32_Printer"   
$objPrint.psbase.scope.options.EnablePrivileges = $true 

## Loop through and create each printer 
For($i=0; $i -lt $PrinterName.count; $i++) 
{ 
$objNewPrinter = $objPrint.createInstance() 
$objNewPrinter.DeviceID = $PrinterName[$i] ## This is the printer name 
$objNewPrinter.DriverName = $PrintDriver[$i] 
$objNewPrinter.PortName = $PrinterPort[$i] 
$objNewPrinter.Location = $Location[$i] 
$objNewPrinter.Comment = $Comment[$i] 
$objNewPrinter.ShareName = $PrinterName[$i] 
$objNewPrinter.Put() 
$objPrint
## Add Security group 
## Not completed yet 
} 

有谁对什么是一般故障以及如何对其进行故障排除有任何想法吗?

Am having major difficulties getting a script I am working on to to successfully create a Printer. I have so far managed to get the Printer Ports created successfully but it always errors with the Printer creation.

The CSV file where it is picking the information up from looks like this:

PrinterName,PrinterPort,IPAddress,Location,Comment,PrintDriver,
Testprint1,Testport1,10.10.10.10,IT_Test,Test_1,HP LaserJet 4200 PCL 5e,

The error message I get is this:

Exception calling "Put" with "0" argument(s): "Generic failure "
At C:\myversion.ps1:53 char:19
+ $objNewPrinter.Put <<<< () 
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

The code I am using is this:

trap { $error[0].Exception | get-member } $objNewPrinter.Put()

Write-Host ("`tCreating " + $strPrinterName.Count + " Printer's`t") 
$objPrint = [WMICLASS]"\\timvista\ROOT\cimv2:Win32_Printer"   
$objPrint.psbase.scope.options.EnablePrivileges = $true 

## Loop through and create each printer 
For($i=0; $i -lt $PrinterName.count; $i++) 
{ 
$objNewPrinter = $objPrint.createInstance() 
$objNewPrinter.DeviceID = $PrinterName[$i] ## This is the printer name 
$objNewPrinter.DriverName = $PrintDriver[$i] 
$objNewPrinter.PortName = $PrinterPort[$i] 
$objNewPrinter.Location = $Location[$i] 
$objNewPrinter.Comment = $Comment[$i] 
$objNewPrinter.ShareName = $PrinterName[$i] 
$objNewPrinter.Put() 
$objPrint
## Add Security group 
## Not completed yet 
} 

Does anyone have any thoughts about what a generic failure is and how to go about troubleshooting it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿与i 2024-11-03 21:44:53

Tim,当将错误参数传递给 WMI 方法时,会引发 Generic failure 错误,因此有两个建议,首先尝试使用真实端口名称而不是 Testport1 并检查 DriverName必须是现有驱动程序的确切名称。

Tim, the Generic failure error is raised when bad parameters are passed to a WMI method, so two advices, first try using a real port name not Testport1 and check for the DriverName must be the exact name of a existing driver.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文