Solved

Script or GPO to unstall Printers and reinstall them

Posted on 2009-07-10
15
188 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Title # Comments Views Activity
Windows IPv6 DHCP server 8 60
Questions about DHCP migration 5 61
How do I disable FTP on a Windows 2008 and 2012 server? 8 41
how do i add admin console 4 26
Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
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…

772 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