Advertisement
Guest User

Import-Printers.ps1

a guest
Sep 18th, 2014
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. ###########################################################################"
  2. #
  3. # NAME: Create-Printers.ps1
  4. #
  5. # AUTHOR: Jan Egil Ring
  6. # EMAIL: jan.egil.ring@powershell.no
  7. # BLOG: http://blog.powershell.no
  8. #
  9. # COMMENT: Simple script to bulk-create printers on a print-server. Printers are imported from a csv-file.
  10. # Running the script from Windows Server 2003 returns an access denied error, possibly due to the impersonation-model in Windows Server 2003.
  11. # Created and tested from Windows Server 2008 against a remote Windows Server 2003 print-server.
  12. # Should work from Windows Vista, Windows 7, Windows Server 2008 and Windows Server 2008 R2 against remote print-servers (2000/2003/2008/2008 R2)
  13. #
  14. # You have a royalty-free right to use, modify, reproduce, and
  15. # distribute this script file in any way you find useful, provided that
  16. # you agree that the creator, owner above has no warranty, obligations,
  17. # or liability for such use.
  18. #
  19. # VERSION HISTORY:
  20. # 1.0 07.11.2009 - Initial release
  21. #
  22. ###########################################################################"
  23.  
  24. function CreatePrinter {
  25. $server = $args[0]
  26. $print = ([WMICLASS]“\\.\ROOT\cimv2:Win32_Printer”).createInstance()
  27. $print.drivername = $args[1]
  28. $print.PortName = $args[2]
  29. $print.Shared = $true
  30. $print.Published = $false
  31. $print.Sharename = $args[3]
  32. $print.Location = $args[4]
  33. $print.Comment = $args[5]
  34. $print.DeviceID = $args[6]
  35. $print.Put()
  36. }
  37.  
  38. function CreatePrinterPort {
  39. $server = $args[0]
  40. $port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
  41. $port.Name= $args[1]
  42. $port.SNMPEnabled=$false
  43. $port.Protocol=1
  44. $port.HostAddress= $args[2]
  45. $port.Put()
  46. }
  47.  
  48. $printers = Import-Csv C:\Users\mywickusernamehere\Desktop\printer.csv
  49.  
  50. foreach ($printer in $printers) {
  51. CreatePrinterPort $printer.Printserver $printer.Portname $printer.IPAddress
  52. CreatePrinter $printer.Printserver $printer.Driver $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.Printername
  53. }
  54.  
  55. Here is the printers.csv
  56. Printserver,Driver,Portname,HostAddress,Sharename,Location,Comment,Printername
  57. location-servername,PCL6 Driver for Universal Print,IP_172.xx.xx.xx,172.xx.xx.xx,Location-PA-MP6002,,,Location-PA-MP6002
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement