newpersn Posted August 28, 2014 Posted August 28, 2014 Hi, We map our printers via a vb script. During the summer we set up a new print server and killed off the old one. Most of the computers are still setting the old print servers printers as the default but installing the new printers from the new system. The old Print server is now turn off and we need a way to delete the old printers from all the computers/users Any help?
Steve21 Posted August 28, 2014 Posted August 28, 2014 You can either add at the start of your map printers a delete part for all network printers, or just deploy a GPO to delete all printers first? Guess it depends if there's a reason you're using scripts still edit - Random stolen etc - strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * From Win32_Printer Where Network = True") For Each objPrinter in colInstalledPrinters objPrinter.Delete_ Next Steve
Duke5A Posted August 28, 2014 Posted August 28, 2014 Do it this way so you don't nuke every installed printer: Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer",,48) On Error Resume Next For Each objPrinter in colInstalledPrinters If InStr(LCase(objPrinter.Name), "OLDSERVERNAMEHERE") Then objNetwork.RemovePrinterConnection objPrinter.Name End If Next If Error <> 0 Then 'Just catch the error, moving on Else 'Nothing to see here folks, move along. End If Just replace OLDSERVERNAMEHERE with the old printer server's name.
Arthur Posted August 28, 2014 Posted August 28, 2014 Should you need it, here's a one line PowerShell script that deletes all printers that reference an old printer server. I had to use this recently myself when GPP didn't work. Get-WmiObject -Class Win32_Printer -Namespace 'root\CIMV2' -Filter "SystemName='\\\\[color="#FF0000"]OLDSERVERNAMEHERE[/color]'" -ErrorAction SilentlyContinue | ForEach { $_.delete() } Much simpler than VBScript! 1
CHiLL Posted November 19, 2015 Posted November 19, 2015 I know this is an old thread, but this is exactly what I am trying to do! I've got this script to delete all network printers: Get-WMIObject Win32_Printer | where{$_.Network -Contains 'true'} | foreach{$_.delete()} It works without issues on my machine, however it will not work at all if the user logged on is a member of staff or student. I'm thinking its down to permissions, but I don't know where to start. Also, if a member of staff or a student has a PS script running as a Logon script...are they able to use the ADSI feature by default, or do they not have permissions to that either?
HPlum78 Posted November 19, 2015 Posted November 19, 2015 remove-printer depends on O/S I think its native in 2012/ 8 and don't know if it is part of the latest WMF.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now