Adding printer from print server

Hi All,

We are migrating to a new print server, and i am writing a script to detect a users installed printers, change the server name and re add the printers (and also set the default printer). This is to be deployed from SCCM 2012 R2

The problem is that the deployment runs but doesn’t migrate any of the printers - when run manually, the script asks for drivers to be installed for certain printers.

Is there a way to bypass this in pwershell?

I have already tried to get around the problem in SCCM but it hasnt worked.

My Script is below.

Thanks in advance for your help :slight_smile:

$net = New-Object -ComObject WScript.Network

$oldqueues = Get-WmiObject -Class Win32_Printer | Where-Object ServerName -Like ‘\ukhem02001*’ | select Name -ExpandProperty Name

$default = Get-WmiObject -Class Win32_Printer | Where-Object Default -EQ ‘True’| select Name -ExpandProperty Name

$default = $default.Replace(“oldprintserver”,“newprintserver”)

foreach ($queue in $oldqueues){
$path = $queue.Replace(“oldprintserver”,“newprintserver”)

$net.AddWindowsPrinterConnection("$path")

    $net.RemovePrinterConnection("$queue")
}

$net.SetDefaultPrinter(“$default”)

Make sure the printer drivers for the specific operating system and architecture exist on the new print server, but I’m going to assume that’s already been done. I’m guessing that user access control (UAC) is enabled on the client computers. More than likely the prompt is due to UAC and applying a group policy that disables “Point and Print Restrictions” on the computers should resolve the issue.

I did something very similar to this, but using Group Policy logon scripts and WMI to add the printers vs. a COM object. It may or may not be useful but we didn’t have any issues with driver popups. But that could have also been the GPO setting that Mike mentioned.

http://learn-powershell.net/2012/11/15/use-powershell-logon-script-to-update-printer-mappings/