Question:
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:
1 2 3 |
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:
1 2 3 4 5 6 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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?
Answer:
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.