PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Replace Users Printers via Script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Replace Users Printers via Script

Réponse
 
LinkBack Outils de la discussion
Vieux 09/10/2007, 17h00   #1
Beanz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Replace Users Printers via Script

I am looking for guidance with the following:

150+ users connected to various printers via one Windows Server 2003
print server. The current print server is on its last legs so we have
moved the printers on to a new server and now need to connect the
users to the new server.

Does that make sense?

As I see it the steps are:

- Enumerate currently installed printers
- Install the same printer but from the new server
- Delete the "old" printer.


Can anyone offer any guidance?


Beanz

  Réponse avec citation
Vieux 09/10/2007, 19h03   #2
Harvey Colwell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Replace Users Printers via Script

> 150+ users connected to various printers via one Windows Server 2003
> print server. The current print server is on its last legs so we have
> moved the printers on to a new server and now need to connect the
> users to the new server.
>



Here is a script that I wrote for a customer. They had 15 prints that needed
to be migrated, I've cut the number down here to save space (Lines 35-39).

The script works by the information stored in the array aPrinters (Line 35).
Each element of this array is a separate array containing two elements. The
first element is the old printer's UNC (\\PServer1\Printer1) and the second
element if the new printer's UNC (\\PServer2\Printer1). You can also just
remove printers that no longer exist on the new Print Server by making the
second element the word "Remove" (Line 37).


The script can be called from the login script or ran manually.

A separate log file is created for each computer. The customer wanted the
logs put on the a network share S:\Printers\Log\<computername>.log (Line
48). The log file has a line for each printer found on the local PC stating
the local printer's name and migration status, "No match found!" (not listed
in the array), "Remove Only", "Successfully Migrated", or "Not Migrated"
(some error occurred while migrating).

Each line of the listing below is preceded by a line number. If not, then
your email client has wrapped the line. Be sure to combined all wrapped
lines then remove the line numbers.


[--- Begin: Migrate Printers.vbs ---]

001. ' Windows Script Host - VBScript
002. '------------------------------------------------
003. ' Name: Migrate Printers.vbs
004. ' By: Harvey Colwell
005. ' CopyRight: (c) Apr 2001, All Rights Reserved!
006. '
007. '************************************************
008.
009. Option Explicit
010.
011. Dim oFS, oWS, oWN, oSA, oSF, oWE, oRE
012.
013. Set oWS = WScript.CreateObject("WScript.Shell")
014. Set oWN = WScript.CreateObject("WScript.Network")
015. Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
016. Set oSA = CreateObject("Shell.Application")
017. Set oSF = oWS.SpecialFolders
018. Set oWE = oWS.Environment
019. Set oRE = new RegExp
020.
021. oRE.IgnoreCase = True
022. oRE.Global = True
023.
024.
025. Dim aPrinters, sPrinter, oPrinters, iIndex1, iIndex2
026. Dim sMSG : sMSG = ""
027.
028. Const sTitle = "Printer Setup"
029.
030. '----------
031. ' Site Setup
032. '----------
033.
034. ' Old Printer New Corresponding Printer
035. aPrinters = array(array("\\PServer1\Bookkeeping",
"\\PServer2\Operations"), _
036. array("\\PServer1\Upstairs", "\\PServer2\Upstairs"), _
037. array("\\PServer1\Canon", "Remove"), _
038. array("\\PServer1\Teller", "\\PServer2\Teller"), _
039. array("\\PServer1\Wires", "\\PServer2\Wires"))
040.
041.
042.
043. '----------
044. ' Local Setup
045. '----------
046. Dim sComputer : sComputer = oWN.ComputerName
047. ' Dim sLog : sLog = oWS.ExpandEnvironmentStrings("%temp%") & "\" &
oFS.GetTempName
048. Dim sLog : sLog = "S:\Printers\Log\" & sComputer & ".log"
049.
050. On Error Resume Next
051. Err.Clear
052.
053. Set oPrinters = oWN.EnumPrinterConnections
054.
055. If Err.Number <> 0 Then call CleanUp("ERROR: Could not list current
Printer Connections!")
056. If oPrinters.Count = 0 Then call CleanUp("ERROR: No network
connection printers found!")
057.
058.
059. For iIndex1 = 0 To oPrinters.Count-1 Step 2
060. For iIndex2 = 0 To UBound(aPrinters)
061.
062. sMSG = Pad(iIndex1/2,2,"0") & ". " &
Fill(UCase(oPrinters(iIndex1 +1)),40, " ")
063.
064.
065. If UCase(oPrinters(iIndex1 +1)) = UCase(aPrinters(iIndex2)(0))
Then
066.
067. On Error Resume Next
068. Err.Clear
069.
070. oWN.RemovePrinterConnection aPrinters(iIndex2)(0), True
071.
072. If UCase(aPrinters(iIndex2)(1)) <> "REMOVE" Then
073. oWN.AddWindowsPrinterConnection aPrinters(iIndex2)(1)
074. If Err.Number <> 0 Then sMSG = sMSG & Fill("Successfully
Migrated", 25, " ") Else sMSG = sMSG & Fill("Not

Migrated!", 25, " ")
075. Else
076. sMSG = sMSG & Fill("Removed Only!", 25, " ")
077. End If
078.
079. On Error Goto 0
080.
081. Else
082. sMSG = sMSG & Fill("No match found!", 15, " ")
083. End If
084. Next
085. LogMsg(sMSG)
086. Next
087.
088.
089. On error Goto 0
090.
091. '----------
092. ' Clean Up
093. '----------
094.
095. ' oWS.Run "notepad.exe " & sLog
096.
097. Call CleanUp("")
098.
099. '---------------------
100. Sub CleanUp(sExitMsg)
101. If Not sExitMsg = "" Then
102. MsgBox sExitMsg, , "Exit Message"
103. End If
104.
105. Set oRE = Nothing
106. Set oWE = Nothing
107. Set oSF = Nothing
108. Set oSA = Nothing
109. Set oWS = Nothing
110. Set oWN = Nothing
111. Set oFS = Nothing
112. WScript.Quit(0)
113. End Sub
114.
115. '----------------------
116. Sub LogMsg(sMsg)
117. Dim oFile
118. If sLog <> "" Then
119. Set oFile = oFS.OpenTextFile(sLog,8,True)
120. oFile.WriteLine sMsg
121. oFile.Close
122. Set oFile = Nothing
123. End If
124. End Sub
125.
126. '---------------------
127. Function Pad(Value, Width, Char)
128. Pad = Right(String(Width, CStr(Char)) & CStr(Value), Width)
129. End Function
130.
131. '---------------------
132. Function Fill(Value, Width, Char)
133. Fill = Left(CStr(Value) & String(Width, CStr(Char)), Width)
134. End Function

[--- End: Migrate Printers.vbs ---]


  Réponse avec citation
Vieux 10/10/2007, 11h04   #3
Beanz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Replace Users Printers via Script


On Oct 9, 7:03 pm, "Harvey Colwell" <HarveyColw...@effingham.net>
wrote:
>
> Here is a script that I wrote for a customer. They had 15 prints that needed
> to be migrated, I've cut the number down here to save space (Lines 35-39).
>
> The script works by the information stored in the array aPrinters (Line 35).
> Each element of this array is a separate array containing two elements. The
> first element is the old printer's UNC (\\PServer1\Printer1) and the second
> element if the new printer's UNC (\\PServer2\Printer1). You can also just
> remove printers that no longer exist on the new Print Server by making the
> second element the word "Remove" (Line 37).
>
> The script can be called from the login script or ran manually.
>
> A separate log file is created for each computer. The customer wanted the
> logs put on the a network share S:\Printers\Log\<computername>.log (Line
> 48). The log file has a line for each printer found on the local PC stating
> the local printer's name and migration status, "No match found!" (not listed
> in the array), "Remove Only", "Successfully Migrated", or "Not Migrated"
> (some error occurred while migrating).
>
> Each line of the listing below is preceded by a line number. If not, then
> your email client has wrapped the line. Be sure to combined all wrapped
> lines then remove the line numbers.


Your script was perfect! Thanks very much!

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12247 seconds with 11 queries