Compare printers on printer servers

Right now I´m working on removing two old printer servers that should have been powered of a couple of years ago. Unfortunately we still have some GPOs mapping the printers to some users with VB scripts. Therefore I need to find out if we have printers on the old servers that haven’t been migrated to the new servers, to accomplish that I collected all printers from the old and new printer servers in different variables and then used compare-object on the printers portname. On the new printer servers we have chosen to place all Toshiba-printers on one server and all Oki and HP on another one, therefore I could easily separate Toshiba printers from the others with an if else  statement filtering on the driver name. The result is a list of all printers that don’t exist on the new servers displaying which printer server the printer exist on and which printer server it needs to be installed on:

“The printer PRN0422 exists on srv-print04 and needs to be installed on srv-print08”

Now the printer/GPO-guy can install the printers on the correct servers and replace the Vb scripts with preferences mapping the same printers but on the new servers.

 

#Get all printers
$srvprint04 = Get-printer -ComputerName srv-print04
$srvprint05 = Get-Printer -ComputerName srv-print05
$srvprint07 = Get-Printer -ComputerName srv-print07
$srvprint08 = Get-Printer -ComputerName srv-print08

#Collect old and new printers in diffrent variables
$printers1 = $srvprint04 + $srvprint05
$printers2 = $srvprint07 + $srvprint08

#Compare if printers exists on new server
$allold= Compare-Object -ReferenceObject $printers2.portname -DifferenceObject $printers1.portname -IncludeEqual | where sideindicator -EQ "=>"

#Display which old server the printer is installed on and which new server it needs to be installed on.
foreach ($printer in $printers1)
{ if ($allold.inputobject -contains $printer.portname   )
  {if ($printer.drivername -like "*tosh*")
    {Write-Host The printer $printer.PortName exists on $printer.ComputerName and needs to be installed on srv-print07
      }
      else
      {Write-Host The printer $printer.PortName exists on $printer.ComputerName and needs to be installed on srv-print08}
  
    }