Solved

Script or GPO to unstall Printers and reinstall them

Posted on 2009-07-10
15
185 Views
Last Modified: 2012-05-07
I'm in the process of moving my print server to a new 2008 box.  Is there a way to unstall the printers from all the desktops and reinstall them via a group policy or bat file? Not everyone uses the same printers
0
Comment
Question by:tbonehwd
  • 10
  • 5
15 Comments
 
LVL 38

Expert Comment

by:Shift-3
ID: 24824486
Paste the script below into a text file with a .vbs extension.  Customize the value of the strOldServer variable on line 1 with the name of the old print server.  Customize the value of the strNewServer variable on line 2 with the name of the new print server.  Running the script will find all printers mapped to the old server and re-map them to the new server using the same share names.

This could be run as a logon script.


strOldServer = "printserver"

strNewServer = "new-printserver"
 

On Error Resume Next
 

Set objNetwork = CreateObject("WScript.Network")

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
 

Set colInstalledPrinters = objWMIService.ExecQuery _

    ("Select * From Win32_Printer")
 

For Each objPrinter in colInstalledPrinters

    If LCase(objPrinter.ServerName) = "\\" & LCase(strOldServer) Then

        strNewPrinter = "\\" & strNewServer & "\" & objPrinter.ShareName

        objNetwork.AddWindowsPrinterConnection strNewPrinter

        

        If objPrinter.Default = "True" Then

            objNetwork.SetDefaultPrinter strNewPrinter

        End If

        

        objPrinter.Delete_

    End If

Next

Open in new window

0
 

Author Comment

by:tbonehwd
ID: 24824497
Can you do this via group policy in 2008?
0
 

Author Comment

by:tbonehwd
ID: 24826365
i'm going to try this and I'll let you know. Thanks in advance.
0
 

Author Comment

by:tbonehwd
ID: 24826501
stupid question.  leave the "'s?
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24826591
Yes, leave the quotation marks.
0
 

Author Comment

by:tbonehwd
ID: 24826831
it's not working. I tried running the script on the machine and nothing happens.
0
 

Author Comment

by:tbonehwd
ID: 24826863
This is what I did.
strOldServer = "hcidc02"
strNewServer = "hcidc2"
 
On Error Resume Next
 
Set objNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
 
Set colInstalledPrinters = objWMIService.ExecQuery _
    ("Select * From Win32_Printer")
 
For Each objPrinter in colInstalledPrinters
    If LCase(objPrinter.ServerName) = "\\" & LCase(hcidc02) Then
        hcidc2 = "\\" & hcidc2 & "\" & objPrinter.ShareName
        objNetwork.AddWindowsPrinterConnection hcidc2
       
        If objPrinter.Default = "True" Then
            objNetwork.SetDefaultPrinter hcidc2
        End If
       
        objPrinter.Delete_
    End If
Next
0
Why do Marketing keep bothering you?

Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

 
LVL 38

Expert Comment

by:Shift-3
ID: 24826954
No, per the instructions the only lines you should be editing are 1 and 2.


strOldServer = "hcidc02"

strNewServer = "hcidc2"

 

On Error Resume Next

 

Set objNetwork = CreateObject("WScript.Network")

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

 

Set colInstalledPrinters = objWMIService.ExecQuery _

    ("Select * From Win32_Printer")

 

For Each objPrinter in colInstalledPrinters

    If LCase(objPrinter.ServerName) = "\\" & LCase(strOldServer) Then

        strNewPrinter = "\\" & strNewServer & "\" & objPrinter.ShareName

        objNetwork.AddWindowsPrinterConnection strNewPrinter

        

        If objPrinter.Default = "True" Then

            objNetwork.SetDefaultPrinter strNewPrinter

        End If

        

        objPrinter.Delete_

    End If

Next

Open in new window

0
 

Author Comment

by:tbonehwd
ID: 24826961
I tried that origionally.  I'll try again.
0
 

Author Comment

by:tbonehwd
ID: 24826991
Ok that deleted the printers but it didn't install them.
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24827146
Are the printers on the new server shared under the same names as on the old server?
0
 

Author Comment

by:tbonehwd
ID: 24827174
No I made sure to make them different.  They are simular but not the same.
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 24827218
Ah, well that will prevent this script from working.  It attempts to re-map them to the same names.
0
 

Author Comment

by:tbonehwd
ID: 24827230
OK If that's all it is I'll rename the shares to match and try that.  i'll get back to you on Monday.  Thanks.
0
 

Author Closing Comment

by:tbonehwd
ID: 31602092
Thanks for your help. The script worked.  I appreciated all your efforts.
0

Featured Post

Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

Join & Write a Comment

I was asked if I could set up a fax machine so that incoming faxes were delivered to people's Exchange inboxes and so that they could send faxes from their desktops without needing to print the document first.  I knew it was possible but I had no id…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now