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

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

 

April 1st, 2010 9:34pm

This must come from HERE ?  I don't have a complete test environment.  This could be an R2 issue...

I'll have to try this on Server 2008 also.

I'm trying it locally for now.  Can you confirm the same issue locally on R2?

  • Proposed as answer by PRDIT Monday, February 04, 2013 5:05 PM
Free Windows Admin Tool Kit Click here and download it now
April 1st, 2010 9:46pm

This must come from HERE ?  I don't have a complete test environment.  This could be an R2 issue...

I'll have to try this on Server 2008 also.

I'm trying it locally for now.  Can you confirm the same issue locally on R2?

  • Proposed as answer by PRDIT Monday, February 04, 2013 5:05 PM
April 1st, 2010 9:46pm

This must come from HERE ?  I don't have a complete test environment.  This could be an R2 issue...

I'll have to try this on Server 2008 also.

I'm trying it locally for now.  Can you confirm the same issue locally on R2?

  • Proposed as answer by PRDIT Monday, February 04, 2013 5:05 PM
Free Windows Admin Tool Kit Click here and download it now
April 1st, 2010 9:46pm

This must come from HERE ?  I don't have a complete test environment.  This could be an R2 issue...

I'll have to try this on Server 2008 also.

I'm trying it locally for now.  Can you confirm the same issue locally on R2?

April 2nd, 2010 12:46am

Yes the srcipt comes from powershell code repository & i confirm: same issue locally on R2.
Free Windows Admin Tool Kit Click here and download it now
April 2nd, 2010 9:11am

Hi guys

 

Did either of you sort this out?  I have a script that runs fine on 2003 by not on Windows 2008 64bit

Many thanks

April 26th, 2010 9:48pm

I'm sorry, I haven't.  I'll try to find some time to look at it.
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2010 4:47am

*bump*

 

I was curious if anyone was able to find a solution to this problem?  If it worked for me it would make life so much easier.

February 11th, 2011 11:59pm

I just ran through these commands on 2008 R2 Enterprise with no issues. I would try adding the printer with commands outside of the function to narrow it down to a problem with how the arguments are being passed, or if it's something with the driver being specified.

 

PS C:\> $port = [wmiclass]"Win32_TcpIpPrinterPort"
PS C:\> $newPort = $port.CreateInstance()
PS C:\> $newPort.name = "IP_192.168.1.21"
PS C:\> $newPort.Protocol = 1
PS C:\> $newPort.HostAddress = "192.168.1.21"
PS C:\> $newPort.PortNumber = "9100"
PS C:\> $newPort.Put()


Path     : \\.\root\cimv2:Win32_TCPIPPrinterPort.Name="IP_192.168.1.21"
RelativePath : Win32_TCPIPPrinterPort.Name="IP_192.168.1.21"
Server    : .
NamespacePath : root\cimv2
ClassName   : Win32_TCPIPPrinterPort
IsClass    : False
IsInstance  : True
IsSingleton  : False



PS C:\> $wmiPrinter = [wmiclass]"Win32_Printer"
PS C:\> $newPrinter = $wmiPrinter.CreateInstance()
PS C:\> $newPrinter.DriverName = "HP LaserJet 4100 Series PCL6"
PS C:\> $newPrinter.PortName = "IP_192.168.1.21"
PS C:\> $newPrinter.DeviceID = "TestPrinter"
PS C:\> $newPrinter.Put()


Path     : \\.\root\cimv2:Win32_Printer.DeviceID="TestPrinter"
RelativePath : Win32_Printer.DeviceID="TestPrinter"
Server    : .
NamespacePath : root\cimv2
ClassName   : Win32_Printer
IsClass    : False
IsInstance  : True
IsSingleton  : False



PS C:\>

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2011 4:32am

I tried on different 2008 R2 boxes, and got the same error.

Win7 x64 works like a charm.

Seems to be a bug for me in 2008 R2

April 16th, 2011 9:44pm

Could someone post a sample of the CSV file they are using.
Free Windows Admin Tool Kit Click here and download it now
August 9th, 2011 10:27pm

I had the same issue until I added a : after the port. 

September 4th, 2012 8:11pm

I had the exact same issue.

Turned out my .CSV file had ; as a seperator. Changed that into a , and everything worked just fine.

  • Proposed as answer by Arjan Mensch Wednesday, February 27, 2013 5:48 PM
Free Windows Admin Tool Kit Click here and download it now
February 27th, 2013 5:48pm

I had the exact same issue.

Turned out my .CSV file had ; as a seperator. Changed that into a , and everything worked just fine.

  • Proposed as answer by Arjan Mensch Wednesday, February 27, 2013 5:48 PM
February 27th, 2013 5:48pm

I had the exact same issue.

Turned out my .CSV file had ; as a seperator. Changed that into a , and everything worked just fine.

  • Proposed as answer by Arjan Mensch Wednesday, February 27, 2013 5:48 PM
Free Windows Admin Tool Kit Click here and download it now
February 27th, 2013 5:48pm

I had the exact same issue.

Turned out my .CSV file had ; as a seperator. Changed that into a , and everything worked just fine.

February 27th, 2013 8:48pm

Any thoughts on how to do this for LPR/LPD printers?

I know you can do this to create the port

               Add-PrinterPort -HostName PrintServerB -PrinterName LPR_123

Very curious on this line:

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

I can get this to work on a 2012 server without issues..  (For TCPIP)  but want to modify it for LPR

----

Or is it this  simple?  Not sure..  testing but looking for help. 

function CreatePrinterPort {

$server =  $args[0]

$port.Name= $args[1]

$port.LPRAddress= $args[2]

$port.Put()

}

Any help appreciated...


  • Edited by BobSha Thursday, May 02, 2013 7:53 PM
Free Windows Admin Tool Kit Click here and download it now
May 2nd, 2013 7:51pm

Any thoughts on how to do this for LPR/LPD printers?

I know you can do this to create the port

               Add-PrinterPort -HostName PrintServerB -PrinterName LPR_123

Very curious on this line:

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

I can get this to work on a 2012 server without issues..  (For TCPIP)  but want to modify it for LPR

----

Or is it this  simple?  Not sure..  testing but looking for help. 

function CreatePrinterPort {

$server =  $args[0]

$port.Name= $args[1]

$port.LPRAddress= $args[2]

$port.Put()

}

Any help appreciated...


  • Edited by BobSha Thursday, May 02, 2013 7:53 PM
May 2nd, 2013 7:51pm

Any thoughts on how to do this for LPR/LPD printers?

I know you can do this to create the port

               Add-PrinterPort -HostName PrintServerB -PrinterName LPR_123

Very curious on this line:

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

I can get this to work on a 2012 server without issues..  (For TCPIP)  but want to modify it for LPR

----

Or is it this  simple?  Not sure..  testing but looking for help. 

function CreatePrinterPort {

$server =  $args[0]

$port.Name= $args[1]

$port.LPRAddress= $args[2]

$port.Put()

}

Any help appreciated...


  • Edited by BobSha Thursday, May 02, 2013 7:53 PM
Free Windows Admin Tool Kit Click here and download it now
May 2nd, 2013 7:51pm

Any thoughts on how to do this for LPR/LPD printers?

I know you can do this to create the port

               Add-PrinterPort -HostName PrintServerB -PrinterName LPR_123

Very curious on this line:

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

I can get this to work on a 2012 server without issues..  (For TCPIP)  but want to modify it for LPR

----

Or is it this  simple?  Not sure..  testing but looking for help. 

function CreatePrinterPort {

$server =  $args[0]

$port.Name= $args[1]

$port.LPRAddress= $args[2]

$port.Put()

}

Any help appreciated...


May 2nd, 2013 10:51pm

I've tried a variation of this script and it works nicely; however, after adding the list of printers, I noticed that none of them were listed in the directory.

Is there anyway to publish the printer via script?

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2013 2:41pm

I am having the same problem. Server 2008 R2. Here is a sample of the csv file

printServer,Driver,portName,shareName,location,comment,printerName
scfmfvm001,"Lexmark Universal v2 PS3",CCC_177L_Optra630,CCC_177L_Optra630,"Added to DHCP DRIP0851",CCC_177L_Optra630

July 15th, 2013 1:04pm

The reason that this it is failing on the create printer is because the port associated with the printer doesn't exist I would confirm that it actually created the port.  When we were working on a similar script we found that it was caused by the port not being created.
Free Windows Admin Tool Kit Click here and download it now
July 26th, 2013 2:17pm

I am having issue with this same script. I have the CSV setup properly from what I can tell:

CSV File:

Printserver,Driver,IPAddress,Portname,Sharename,Location,Comment,Printername
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.60,10.241.200.60,DEV_MAIN_P2,Development Office,,DEV_MAIN_P2
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.61,10.241.200.61,DEV_MAIN_P3,Development,,DEV_MAIN_P3

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:\PrinterImport.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
}

When I run the script on the Print Server (2008 R2) it opens the PS window quickly then closes, with no errors or anything that makes me think an issue happened with the script. Issue is that none of the printers actually show on the server. It seems to do nothing at all. 

Please Help me out as I have around 2000 printers I need to build and want to do them quickly.


April 16th, 2015 1:20pm

I am having issue with this same script. I have the CSV setup properly from what I can tell:

CSV File:

Printserver,Driver,IPAddress,Portname,Sharename,Location,Comment,Printername
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.60,10.241.200.60,DEV_MAIN_P2,Development Office,,DEV_MAIN_P2
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.61,10.241.200.61,DEV_MAIN_P3,Development,,DEV_MAIN_P3

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:\PrinterImport.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
}

When I run the script on the Print Server (2008 R2) it opens the PS window quickly then closes, with no errors or anything that makes me think an issue happened with the script. Issue is that none of the printers actually show on the server. It seems to do nothing at all. 

Please Help me out as I have around 2000 printers I need to build and want to do them quickly.


Free Windows Admin Tool Kit Click here and download it now
April 16th, 2015 5:18pm

I am having issue with this same script. I have the CSV setup properly from what I can tell:

CSV File:

Printserver,Driver,IPAddress,Portname,Sharename,Location,Comment,Printername
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.60,10.241.200.60,DEV_MAIN_P2,Development Office,,DEV_MAIN_P2
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.61,10.241.200.61,DEV_MAIN_P3,Development,,DEV_MAIN_P3

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:\PrinterImport.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
}

When I run the script on the Print Server (2008 R2) it opens the PS window quickly then closes, with no errors or anything that makes me think an issue happened with the script. Issue is that none of the printers actually show on the server. It seems to do nothing at all. 

Please Help me out as I have around 2000 printers I need to build and want to do them quickly.


April 16th, 2015 5:18pm

I am having issue with this same script. I have the CSV setup properly from what I can tell:

CSV File:

Printserver,Driver,IPAddress,Portname,Sharename,Location,Comment,Printername
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.60,10.241.200.60,DEV_MAIN_P2,Development Office,,DEV_MAIN_P2
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.61,10.241.200.61,DEV_MAIN_P3,Development,,DEV_MAIN_P3

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:\PrinterImport.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
}

When I run the script on the Print Server (2008 R2) it opens the PS window quickly then closes, with no errors or anything that makes me think an issue happened with the script. Issue is that none of the printers actually show on the server. It seems to do nothing at all. 

Please Help me out as I have around 2000 printers I need to build and want to do them quickly.


Free Windows Admin Tool Kit Click here and download it now
April 16th, 2015 5:18pm

I am having issue with this same script. I have the CSV setup properly from what I can tell:

CSV File:

Printserver,Driver,IPAddress,Portname,Sharename,Location,Comment,Printername
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.60,10.241.200.60,DEV_MAIN_P2,Development Office,,DEV_MAIN_P2
prtsvr01,HP Universal Printing PCL 5 (v5.5.0),10.241.200.61,10.241.200.61,DEV_MAIN_P3,Development,,DEV_MAIN_P3

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:\PrinterImport.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
}

When I run the script on the Print Server (2008 R2) it opens the PS window quickly then closes, with no errors or anything that makes me think an issue happened with the script. Issue is that none of the printers actually show on the server. It seems to do nothing at all. 

Please Help me out as I have around 2000 printers I need to build and want to do them quickly.


April 16th, 2015 5:18pm

For my issue I had to run the script using Admin Tools and the Admin:Win PS Modules then making sure I SetExecution Policy to unrestricted and it worked for me perfectly.
Free Windows Admin Tool Kit Click here and download it now
May 4th, 2015 2:59pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics