?
Solved

Script or GPO to unstall Printers and reinstall them

Posted on 2009-07-10
15
Medium Priority
?
195 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

752 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