创建打印机 Powershell
我在获取我正在编写的脚本来成功创建打印机时遇到了很大的困难。到目前为止,我已成功创建打印机端口,但在创建打印机时总是出错。
它从中获取信息的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 notTestport1
and check for the DriverName must be the exact name of a existing driver.