Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Bulk-create printer objects on windows 2008 R2 x64 print servers using Windows PowerShell

$
0
0

Hi,

I have an issue on a 2008 Server R2 x64 when trying to create a printer with this Powershell script:

function CreatePrinter {

$server = $args[0]

$print = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_Printer").createInstance()

$print.drivername = $args[1]

$print.PortName = $args[2]

$print.Shared = $true

$print.Sharename = $args[3]

$print.Location = $args[4]

$print.Comment = $args[5]

$print.DeviceID = $args[6]

$print.Put()

}

 

function CreatePrinterPort {

$server =  $args[0]

$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()

$port.Name= $args[1]

$port.SNMPEnabled=$false

$port.Protocol=1

$port.HostAddress= $args[2]

$port.Put()

}

 

$printers = Import-Csv c:\printers.csv

 

foreach ($printer in $printers) {

CreatePrinterPort $printer.Printserver $printer.Portname $printer.IPAddress

CreatePrinter $printer.Printserver $printer.Driver $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.Printername

}

The printer port creation work fine, but I have this error on the printer creator:
Exception calling “Put” with “0″ argument(s): “Generic failure ”
At C:\temp\createprinter.ps1:53 char:12
+ $print.Put <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

Note: I first install the drivers manually.

Then i have tried with several win32 drivers and the issue is always the same.

I have tried on windows 2003 and it works like a charm…

Any idea ?

Help would be appreciated

 


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>