Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 HALP! Questions on Windows and Windows Server
 Scripting
 Print Server Deployment
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

allan67
Here To Stay

United Kingdom
280 Posts
Status: offline

Posted - 12/28/2011 :  08:28:21 AM  Show Profile  Click to see allan67's MSN Messenger address  Reply with Quote
Hi everyone, hope u all had a nice xmas.

Now here is a nice little project to work of that turkey. Print servers.. more specifically rapid deployment of print servers, fault tolerance etc.

Situation:
Windows 2008r2 Standard edition servers(no option for failover clustering booooo)

We deploy 2 print servers to each site. Initial idea has been to setup printserver1 then use printbrm to migrate printers from 1 to 2. Then setup a scheduled task to do this each week to ensure that any new printers deployed are also migrated to server 2

The next part is cleanup active directory of published printers

All scripts will be added to the next post. I'm looking for ideas to streamline this process with a 1 click config or other ideas on how to do this

allan67
Here To Stay

United Kingdom
280 Posts
Status: offline

Posted - 12/28/2011 :  08:32:52 AM  Show Profile  Click to see allan67's MSN Messenger address  Reply with Quote
Printer backup and import script which is ran from server 2
CD %WINDIR%\System32\Spool\Tools
Printbrm –s \\server1 –b –f C:\BackupExport\server1.printerExport
Printbrm –r –f C:\BackupExport\server1.printerExport
Go to Top of Page

allan67
Here To Stay

United Kingdom
280 Posts
Status: offline

Posted - 12/28/2011 :  08:34:36 AM  Show Profile  Click to see allan67's MSN Messenger address  Reply with Quote
This powershell script is ran on the second server. It loops through all the installed printers and sets the "list in directory" check box

$printers = gwmi win32_printer
foreach ($printer in $printers)
{
$printer.published = $true
$printer.put()
}
Go to Top of Page

allan67
Here To Stay

United Kingdom
280 Posts
Status: offline

Posted - 12/28/2011 :  08:35:19 AM  Show Profile  Click to see allan67's MSN Messenger address  Reply with Quote
The next part of this process is a scheduled task to run the batch file each week. I haven't got a script for that yet
Go to Top of Page

allan67
Here To Stay

United Kingdom
280 Posts
Status: offline

Posted - 12/28/2011 :  08:36:45 AM  Show Profile  Click to see allan67's MSN Messenger address  Reply with Quote
This is the script that all users would run to flip from server 1 to server 2

SCRIPT START = = = = = = = = = = = = = = = =
'This script works well in a login script. When ran from a workstation
'it will loop thru all of the printers installed for the current logged on
'user and if they are connected to the old server they will be removed
'and then remapped to the new server. It will also attempt to discover
'which printer is the default printer in order to reset this if it is one
'of the printers that will be moved.
'Note: The script does not run if you are Terminal serviced or SMS remote controlling.
Option Explicit
Dim from_sv, to_sv, PrinterPath, PrinterName, DefaultPrinterName, DefaultPrinter
Dim DefaultPrinterServer, SetDefault, key
Dim spoint, Loop_Counter
Dim WshNet, WshShell
Dim WS_Printers
DefaultPrinterName = ""
spoint = 0
SetDefault = 0
set WshShell = CreateObject("WScript.shell")
from_sv = "\\server1" 'This should be the name of the primary server.
to_sv = "\\server2" 'This should be the name of your backup server.
'Just incase there are no printers and therefor no defauld printer set
' this will prevent the script form erroring out.
On Error Resume Next
key = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
DefaultPrinter = LCase(WshShell.RegRead (key))
If Err.Number <> 0 Then
DefaultPrinterName = ""
else
'If the registry read was successful then parse out the printer name so we can
' compare it with each printer later and reset the correct default printer
' if one of them matches this one read from the registry.
spoint = instr(3,DefaultPrinter,"\")+1
DefaultPrinterServer = left(DefaultPrinter,spoint-2)
if DefaultPrinterServer = from_sv then
DefaultPrinterName = mid(DefaultPrinter,spoint,len(DefaultPrinter)-spoint+1)
end if
end if
Set WshNet = CreateObject("WScript.Network")
Set WS_Printers = WshNet.EnumPrinterConnections
'You have to step by 2 because only the even numbers will be the print queue's
' server and share name. The odd numbers are the printer names.
For Loop_Counter = 0 To WS_Printers.Count - 1 Step 2
'Remember the + 1 is to get the full path ie.. \\your_server\your_printer.
PrinterPath = lcase(WS_Printers(Loop_Counter + 1))
'We only want to work with the network printers that are mapped to the original
' server, so we check for "\\Your_server".
if LEFT(PrinterPath,len(from_sv)) = from_sv then
'Now we need to parse the PrinterPath to get rhe Printer Name.
spoint = instr(3,PrinterPath,"\")+1
PrinterName = mid(PrinterPath,spoint,len(PrinterPath)-spoint+1)
'Now remove the old printer connection.
WshNet.RemovePrinterConnection from_sv+"\"+PrinterName
'and then create the new connection.
WshNet.AddWindowsPrinterConnection to_sv+"\"+PrinterName
'If this printer matches the default printer that we got from the registry then
' set it to be the default printer.
if DefaultPrinterName = PrinterName then
WshNet.SetDefaultPrinter to_sv+"\"+PrinterName
end if
end if
Next
Set WS_Printers = Nothing
Set WshNet = Nothing
Set WshShell = Nothing
‘SCRIPT END = = = = = = = = = = = = = = = =
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Mark Minasi's Reader Forum © 2002-2011 Mark Minasi Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000