Tuesday, 21 April 2009

Get-PrinterTestPage.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script uses WMI to print a test page 
  4.     all printers on this system 
  5. .DESCRIPTION 
  6.     This script is an MSDN sample,using PowerShell. It first 
  7.     gets all the printrs installed, prints out details then 
  8.     tries to print a test page. 
  9.      
  10.     The script also checks for printers known to not work well, and avoids using them 
  11. .NOTES 
  12.     File Name  : Get-PrinterTestPage.ps1 
  13.     Author     : Thomas Lee - tfl@psp.co.uk 
  14.     Requires   : PowerShell V2 CTP3 
  15. .LINK 
  16.     Sample posted to: 
  17.         http://pshscripts.blogspot.com/2009/04/get-printertestpageps1.html
  18.     Original MSDN sample at: 
  19.         http://msdn.microsoft.com/en-us/library/aa392757(VS.85).aspx  
  20. .EXAMPLE 
  21.     PSH [C:\foo]: .Get-PrinterTestPage.ps1' 
  22.     4 Printers defined on this system 
  23.     Printer share name: \ 
  24.     Printer Port      : C:\ProgramData\TechSmith\SnagIt 9\PrinterPortFile 
  25.     Printer share name: \Phaser PS 
  26.     Printer Port      : X_10.10.1.117 
  27.     Printer share name: \ 
  28.     Printer Port      : XPSPort: 
  29.     Printer share name: \\SLT-PC\officejet 
  30.     Printer Port      : USB002 
  31.      
  32.     Printing test page for printer: SnagIt 9 
  33.     Not printing a test page for this printer 
  34.     Printing test page for printer: Phaser PS 
  35.     Result                        : 0 
  36.     Printing test page for printer: Microsoft XPS Document Writer 
  37.     Not printing a test page for this printer 
  38.     Printing test page for printer: \\JerryGarcia\HP Officejet Pro L7400 Series 
  39.     Result                        : 0 
  40.     #> 
  41.  
  42. ### 
  43. # Start of Script 
  44. ### 
  45.   
  46. # Get Printer Objects for this computer from WMI 
  47. $printers = Get-WmiObject -Class Win32_Printer 
  48. # Display printers 
  49. "{0} Printers defined on this system" -f $printers.count 
  50.  
  51. # For printers, display printer details 
  52. foreach ($printer in $printers) { 
  53. "Printer share name: {0}\{1}" -f $printer.servername, $printer.sharename 
  54. "Printer Port      : {0}    " -f $printer.PortName   
  55. "" 
  56.  
  57. # Now Print a test page for each printer 
  58. foreach ($printer in $printers) { 
  59. "Printing test page for printer: {0}" -f $printer.name 
  60.  
  61. # avoid issue with Known bad printers
  62. if ($printer.DriverName -match "XPS" -or $printer.DriverName -match "SnagIt")  { 
  63. "Not printing a test page for this printer" 
  64. else
  65. $Result = $printer.PrintTestPage() 
  66. "Result                        : {0}" -f $Result.ReturnValue 
  67. # End of script 
Technorati Tags: ,,,

1 comment:

Troxsa said...

Perfect :)
Thanks you