title: Alternatives to Add-Printer, Remove-Printer etc. for Windows Server 2008 R2
body: <p>I was given the Task of rewriting an old script into PowerShell from VBScript. This script basically just reads a line of a text file and installs the printer corresponding to that line, before removing it again, so that just the driver is installed.</p>
  
  <p>This script gets executed every day on our virtual Citrix terminal servers, this way we can update drivers independently of the current released image.</p>
  
  <p>Here's what the final script looks like:</p>
  
  <pre><code># Variables
  Param([string]$FileName)
  $DriverList = Get-Content $FileName
  $ComputerName = hostname
  $LogFile = "C:\Windows\Logs\PrinterCreation.log"
  $SeperatorL = "═══════════════════════════════════════════════════════════════════════════════════════════════════════"
  $SeperatorS = "═══════════════════════════════════════════"
  $StartDate = Get-Date -Format "dd.MMM.yyyy HH:mm:ss"
  
  # Log Header
  "$SeperatorL" &gt; $LogFile
  " ServerName:   $ComputerName" &gt;&gt; $LogFile
  " DriverList:   $FileName" &gt;&gt; $LogFile
  " StartTime:    $StartDate" &gt;&gt; $LogFile
  "$SeperatorL" &gt;&gt; $LogFile
  "" &gt;&gt; $LogFile
  "Beginning driver instalation process:" &gt;&gt; $LogFile
  
  # Process the "$DriverList" by installing each printer on the list and  deleting the connection afterwards
  foreach ($line in $DriverList) {
      "$SeperatorL" &gt;&gt; $LogFile
      " Print driver Installation:    $line" &gt;&gt; $LogFile
  
      # Installing the printer
      try {
          Add-Printer -ConnectionName $line -ErrorAction Stop
          Start-Sleep -s 10
  
          # Deleting the Printer
          try {
              Remove-Printer -Name $line -ErrorAction Stop
              " Printer installation successfull." &gt;&gt; $LogFile
          } catch {
              " INSTALATION NOT COMPLETE:     Printer was installed but connection could not be removed!" &gt;&gt; $LogFile
          }
      } catch [Microsoft.Management.Infrastructure.CimException] {
          " INSTALATION FAILED:           Printer driver cannot be found or does not exist!" &gt;&gt; $LogFile
      } finally {
          Start-Sleep -s 5
      }
  }
  
  # Log Footnote
  $EndDate = Get-Date -Format "HH:mm:ss"
  "$SeperatorL" &gt;&gt; $LogFile
  "" &gt;&gt; $LogFile
  "Instalation process completed:" &gt;&gt; $LogFile
  "$SeperatorS" &gt;&gt; $LogFile
  " End Time: $EndDate" &gt;&gt; $LogFile
  "$SeperatorS" &gt;&gt; $LogFile
  </code></pre>
  
  <p>It gets called like so: <code>.\scriptfilename.ps1 ".\Driverlist.txt"</code></p>
  
  <p>The driver list just consists of lines like these: <code>"\\spbdn140\KM_Universal_PCL"</code></p>
  
  <p><strong>The Problem in short</strong></p>
  
  <p>When writing this script I hadn't realized that the printer management module only works from Win 8 and Server 2012 upwards. Our terminal servers are all running Server 2008.</p>
  
  <p>Is there any way to achieve what I'm trying to do with the information available (the driver list) in PowerShell v3-4 on Server 2008? </p>
  
  <p>Again, the end result should just be that the drivers are installed on the terminal servers just using the information provided.</p>