Create a Powershell Printer

I'm having serious difficulties getting a script I'm working on to successfully create a printer. So far, I have managed to successfully create printer ports, but there have always been errors when creating the printer.

The CSV file in which it collects information is as follows:

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 the following:

 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 use is:

 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 on what a general failure is and how to fix it?

+4
source share
1 answer

Tim, a Generic failure error occurs when bad parameters are passed to the WMI method, so two Testport1 : first try using the real port name Testport1 and check the name DriverName should be the exact name of an existing driver.

+1
source

Source: https://habr.com/ru/post/1346072/


All Articles