title: I need to add multiple printers to multiple print servers with Powershell and a single .csv file
body: <p>I have a script that will run against an Excel file for a list of printers as well as the the listed print server.</p>
  
  <p>The issue I cant figure out is how to add multiple printers to multiple print servers without having an Excel sheet with 200 lines.</p>
  
  <p>I would like to have the print servers listed in the Powershell script and have the <code>foreach</code> command go through each server listed dynamically.</p>
  
  <p>Here is the code I have so far. I am trying to get the <code>$server</code> to be able to have a list of servers and change the part in the function to the next server on the list.
  I attached an example of what the .csv formatting looks like. <a href="https://i.stack.imgur.com/uYbYp.jpg" rel="nofollow noreferrer">example of the formatting of the .csv file</a> Thanks for any help anyone can provide.</p>
  
  <pre><code>function CreatePrinter {
      $server = $args[0]
      $print = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_Printer").createInstance() 
      $print.drivername = $args[1]
      $print.PortName = $args[2]
      $print.Shared = $false
      $print.Sharename = $args[3]
      $print.Location = $args[4]
      $print.Comment = $args[5]
      $print.DeviceID = $args[6]
      $print.Put() 
  }
  
  function CreatePrinterPort {
      $server =  $args[0] 
      $port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
      $port.Name= $args[1]
      $port.SNMPEnabled=$false 
      $port.Protocol=1 
      $port.HostAddress= $args[2]
      $port.Put() 
  }
  
  $printers = Import-Csv C:\test\NewPrinters.csv
  
  foreach ($printer in $printers) {
      CreatePrinterPort $printer.Printserver $printer.Portname $printer.IPAddress
      CreatePrinter $printer.Printserver $printer.Driver $printer.Portname 
      $printer.Sharename $printer.Location $printer.Comment $printer.Printername
  }
  </code></pre>