title: Nested foreach loops to install printers
body: <p>I have a need to install multiple printers to multiple servers and was wanting to script this so that it would only need to be configured once.</p>
  
  <p>I am using PowerShell to query 2 CSV files; 1 to get a list of computers to install printers too and the other to list the Name, IP, Driver, Location of the needed printers. I am using 2 <code>foreach</code> loops to accomplish this and a <code>break</code> to try to get it to loop correctly.</p>
  
  <p>Currently with the <code>break :outer</code> where it is the first PC gets all printers installed. If I move it to inside the <code>foreach ($printer in $printers)</code> loop it will only install the first printer to all computers.</p>
  
  <p>Thank you for any assistance that anyone can provide.</p>
  
  <pre><code>$computerfile = Import-Csv C:\computerlist.csv
  $printers = Import-Csv C:\printers2.csv 
  
  foreach ($computer in $computerfile) {
      "computer: $computer"
      :outer
      foreach ($printer in $printers) {
          Add-PrinterPort -ComputerName $computer.Name -Name $printer.IP -PrinterHostAddress $printer.IP
          Add-Printer -ComputerName $computer.Name -Name $printer.Name -DriverName $printer.Driver -PortName $printer.IP -ShareName $printer.Name -Location $printer.Location
          Set-printer -ComputerName $computer.Name -Name $printer.Name -Shared $false -Published $true
      }
      break :outer
  }
  </code></pre>