Advertisement
easternnl

Check-PrinterDriver & Get-PrinterDriverVersion

Dec 18th, 2015
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Check-PrinterDriver
  2. {
  3. <#
  4.    .Synopsis
  5.     This function gets the printer driver from the WMI and check if it exist and if the version is correct
  6.    .Description
  7.     This function read the printer driver data from Win32_PrinterDriver and check if the requested driver
  8.     exist and has the correct version (if given)    
  9.    .Example
  10.     Check-PrinterDriver -Name "HP Officejet Pro 8600" -Version "10.0.10586.0"
  11.     Check if the driver for the HP Officejet Pro exist and if the version correspondents with 10.0.10586.0
  12.    .Example
  13.     Check-PrinterDriver -Name "DYMO LabelWriter 450"
  14.     Check if the driver for the DYMO LabelWriter 450 exist, no matter which version
  15.    .Parameter Name
  16.     The name the printer driver has
  17.    .Parameter Version
  18.     The version of the printer driver
  19.    .Notes
  20.     NAME:  Check-PrinterDriver
  21.     AUTHOR: Erik van Oost
  22.     LASTEDIT: 18/12/2015
  23.     KEYWORDS: Printer Drivers    
  24.    .Link
  25.      Http://blog.eastern.nl
  26.  #Requires -Version 3.0
  27.  #>
  28.  Param([string[]]$name, [string[]]$version)
  29.  
  30.     if (Test-Path "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\$name")
  31.     {
  32.         if ($version -eq $null)
  33.         {
  34.             # only check if printerdriver exist
  35.             return $true
  36.         }
  37.         else
  38.         {
  39.             # read version of the printerdrver
  40.             if ((Get-PrinterDriverVersion -name $name) -eq $version)
  41.             {
  42.                 return $true
  43.             }
  44.             else
  45.             {
  46.                 return $false
  47.             }
  48.  
  49.         }
  50.     }
  51.     else
  52.     {
  53.         return $false;
  54.     }
  55. }
  56.  
  57. Function Get-PrinterDriverVersion
  58. {
  59. <#
  60.    .Synopsis
  61.     This function gets the printer driver version from the WMI
  62.    .Description
  63.     This function read the printer driver data from Win32_PrinterDriver and collects the corresponding driver version
  64.    .Example
  65.     Get-PrinterDriverVersion -Name "HP Officejet Pro 8600"
  66.     Returns the driver version of the HP Officejet Pro 8600 printer  
  67.    .Parameter Name
  68.     The name the printer driver has  
  69.    .Notes
  70.     NAME:  Get-PrinterDriverVersion
  71.     AUTHOR: Erik van Oost
  72.     LASTEDIT: 18/12/2015
  73.     KEYWORDS: Printer Drivers    
  74.    .Link
  75.      Http://blog.eastern.nl
  76.  #Requires -Version 3.0
  77.  #>
  78.  Param([string[]]$name)
  79.  
  80.    
  81.     $driverinfo = Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\$name" -ErrorAction sil
  82.     return $driverinfo.DriverVersion
  83.  
  84.  }
  85.  
  86.  
  87. Check-PrinterDriver -name "HP Officejet Pro 8600" -version 9.84.0.1189 -Verbose
  88.  
  89. Check-PrinterDriver -name "HP Officejet Pro 8600"
  90.  
  91. Check-PrinterDriver -Name "DYMO LabelWriter 450"
  92.  
  93. Get-PrinterDriverVersion -name "DYMO LabelWriter 450"
  94. Get-PrinterDriverVersion -name "HP Officejet Pro 8600"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement