+ Post New Thread
Results 1 to 4 of 4
Windows 7 Thread, Removing printers from Computers using the Printer Script in Technical; Hi, We map our printers via a vb script. During the summer we set up a new print server and ...
  1. #1
    newpersn's Avatar
    Join Date
    Nov 2010
    Location
    Gloucestershire
    Posts
    1,389
    Thank Post
    329
    Thanked 127 Times in 91 Posts
    Rep Power
    91

    Removing printers from Computers using the Printer Script

    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?

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,773
    Thank Post
    354
    Thanked 534 Times in 499 Posts
    Rep Power
    183
    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 -
    Code:
    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

  3. #3
    Duke5A's Avatar
    Join Date
    Jul 2010
    Posts
    842
    Thank Post
    87
    Thanked 144 Times in 122 Posts
    Blog Entries
    8
    Rep Power
    34
    Do it this way so you don't nuke every installed printer:

    Code:
    	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.

  4. #4


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,653
    Thank Post
    253
    Thanked 2,918 Times in 2,149 Posts
    Rep Power
    831
    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.

    Code:
    Get-WmiObject -Class Win32_Printer -Namespace 'root\CIMV2' -Filter "SystemName='\\\\OLDSERVERNAMEHERE'" -ErrorAction SilentlyContinue | ForEach { $_.delete() }
    Much simpler than VBScript!



SHARE:
+ Post New Thread

Similar Threads

  1. Powershell - Remove groups from computer
    By FN-GM in forum Windows Server 2012
    Replies: 1
    Last Post: 19th December 2013, 08:19 AM
  2. Using scripts to assign printers to computers
    By Harry_Greatorex in forum Windows 7
    Replies: 12
    Last Post: 25th November 2013, 09:35 AM
  3. how would i use the Index0r script in wordpress
    By krisd32 in forum Web Development
    Replies: 1
    Last Post: 28th June 2012, 07:33 PM
  4. Replies: 4
    Last Post: 21st September 2010, 03:45 PM
  5. Replies: 11
    Last Post: 20th November 2009, 02:07 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •