Bulk-create printer objects on print servers using Windows PowerShell
When installing a new print-server with several hundreds or thousands of printer objects there arent`t too much fun doing this manually.
Here are 3 steps to automate this process:
1) Install all the necessary printer drivers on the printserver
2) Create a csv-file with a listing of all printer objects and their properties
3) Bulk-import the printer objects using a script
For the 3rd step I`ve created a basic Windows PowerShell script, available on PoshCode.org from this link.
The script contains one function for creating a TCP/IP printer port and one function for creating a printer object. These functions are used in a foreach-loop cycling through the csv-file containing all the printer objects. The script are pretty basic, and should be further expanded with error handling and further details for printer properties.
The script are created and tested on a Windows Server 2008 server against a remote Windows Server 2003 server.
Running the script from Windows Server 2003 returns an access denied error, possibly due to the impersonation-model in Windows Server 2003. However, it should work from Windows Vista, Windows 7, Windows Server 2008 and Windows Server 2008 R2 against remote print-servers (2000/2003/2008/2008 R2).
Especially the ability to set NTFS permissions on the printer objects would be a useful addition in the script.
Please feel free to leave suggestions for improvements in the comments section below.
Update 09.11.2009:
I`ve got some feedback regarding the ability to set NTFS permissions on the printer objects in the script.
A utility called SubInACL from Microsoft could be used for this.
Example usage:
subinacl.exe /printer “\\print-server\printer” /revoke=”Power Users”
subinacl.exe /printer “\\print-server\printer” /grant=”DOMAIN\Domain Users”
The tool can be downloaded from here.
Hi,
I have this error on try to create print on windows 2008 R2:
Exception calling “Put” with “0″ argument(s): “Generic failure ”
At C:\Users\administrator.HLUZ\Desktop\createprinter.ps1:53 char:12
+ $print.Put <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Any help?
thanks
Hi! You`re sure the csv-file contains the necessary headers?Printserver,Driver,Portname,Sharename,Location,Comment,Printername.
The same thing happens if you manually try to run the CreatePrinter function?
Hi,
The printer port creating work fine, but I have this error on the printer creator. My CSV=
Printserver,Driver,Portname,IPAddress,Sharename,Location,Comment,Printername
HL-SPRINTER02,Microsoft XPS Document Writer,10.0.19.1,10.0.19.1,HL-P001,teste,teste,HL-P001
I have tried configure the printers settings direct on the CreatePrinter funcition, but show me this error:
PS C:\Users\administrator.HLUZ\Desktop> .\createprinter3.ps1
Unexpected token ‘.19′ in expression or statement.
At C:\Users\administrator.HLUZ\Desktop\createprinter3.ps1:31 char:26
+ $print.PortName = 10.0.19 <<<< .1
+ CategoryInfo : ParserError: (.19:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
Thanks for your helping,
LB
Hi,
After many attempts, the problem is on Microsoft XPS Document Writer… Bad luck on test driver…
Thanks
Hi,
The script work fine but I’m on a Windows 2k8 cluster and when I launch the script it create the printer on the node and not the cluster instance.
Could you tell me what can I do ?
Thanks
WMI does not support the cluster virtual machine name, only node names.
Pick us the Windows Resource Kit and use prnadmin.dll and associated
scripts and support when scripting printers on the cluster.
http://www.microsoft.com/downloads/d…DisplayLang=en
If you have an existing print server, try the print migrator tool if you
wish to move printers from one or more machines to the cluster.
http://www.microsoft.com/WindowsServ…grator3.1.mspx
Source: http://forums.techarena.in/server-cluster/75119.htm
Hi,
I have the same issue as Leao Braz on a 2008 Server R2 x64. 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
Then i have tried with several 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
Thanks