Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Clear connections to the print server

$
0
0

We have a newprint serverandwant to runa scriptonall clientsvia GPO.Itshould beall connections to theoldprint serverdeleted.

$oldPrinterName = "\\Server01\"
$comNetwork = New-Object -ComObject "Wscript.Network"
$printer = gwmi -Class Win32_Printer | ?{$_.Network -eq $true -and $_.ServerName -eq "\\$($oldprinterName.Split("\")[2])" -and $_.ShareName -eq $oldprinterName.Split("\")[3]}
if ($printer) {
$printer | %{$comNetwork.RemovePrinterConnection($_.Name)}
}else{
exit
}

Is this the rightway?


Viewing all articles
Browse latest Browse all 6937

Latest Images

Trending Articles



Latest Images