Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Adding printer from print server

$
0
0

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 :)

$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”)


Viewing all articles
Browse latest Browse all 13067

Trending Articles