Solved

Script or GPO to unstall Printers and reinstall them

Posted on 2009-07-10
15
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
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 the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

733 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