-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathProfileRobocopy.vbs
More file actions
278 lines (221 loc) · 10.1 KB
/
ProfileRobocopy.vbs
File metadata and controls
278 lines (221 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
'*******************************************************************************
' Program: ProfileRobocopy.vbs
' Author: Mick Pletcher
' Date: 04 January 2010
' Modified:
' Description: This script will robocopy a profile from one machine to another.
' It is intended to be used when the USMT fails. The user must
' logon to the new machine before running this script. If this is
' executed before a profile is created, a new profile will be
' created <profile>.xxx and the user will not see any of the
' copied data.
' There needs to be a %NetworkPath%\PSTools directory containing
' PSTools. Robocopy needs to be present in the PSTools directory.
' PSTools allows for the robocopy to run locally on the old
' machine, thereby conserving bandwidth if it is at a remote
' location.
'*******************************************************************************
Option Explicit
REM Define Constants
CONST TempFolder = "c$\temp\"
CONST LogFolderName = "ProfileCopy"
CONST NetworkPath = "\\global.gsp\data\special\Deploy\USMT\"
REM Define Global Variables
DIM NewComputer : Set NewComputer = Nothing
DIM OldComputer : Set OldComputer = Nothing
DIM NewComputerOS : Set NewComputerOS = Nothing
DIM OldComputerOS : Set OldComputerOS = Nothing
DIM LogFolder : Set LogFolder = Nothing
DIM OS : Set OS = Nothing
DIM RelativePath : Set RelativePath = Nothing
DIM ReturnCode : ReturnCode = "0"
DIM UserName : Set UserName = Nothing
REM Define relative installation path
DefineRelativePath()
REM Prompt for Old Computer Name, New Computer Name, and Username
GetComputerInfo()
REM Create the log folder
CreateLogFolder()
REM Determine which OS this script is being run from
DetermineOS()
MSGBOX OldComputerOS & Chr(32) & NewComputerOS
If (OldComputerOS = "WindowsXP") and (NewComputerOS = "WindowsXP") then
REM Robocopy the profile from the old XP machine to the new XP machine
CopyFilesXP2XP()
End If
If (OldComputerOS = "WindowsXP") and (NewComputerOS = "Windows7") then
REM Robocopy the profile from the old XP machine to the new Windows 7 machine
CopyFilesXP2Win7()
End If
If (OldComputerOS = "Windows7") and (NewComputerOS = "Windows7") then
REM Robocopy the profile from the old Windows 7 machine to the new Windows 7 machine
CopyFilesWin72Win7()
End If
REM Verify there were no errors during the robocopy
VerifyCopy()
REM Cleanup Global Variables
GlobalMemoryCleanup()
'*******************************************************************************
'*******************************************************************************
Sub DefineRelativePath()
REM Get File Name with full relative path
RelativePath = WScript.ScriptFullName
REM Remove file name, leaving relative path only
RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))
End Sub
'*******************************************************************************
Sub GetComputerInfo()
OldComputer = InputBox( "Enter the old computer name:" )
NewComputer = InputBox( "Enter the new computer name:" )
UserName = InputBox( "Enter the username:" )
End Sub
'*******************************************************************************
Sub CreateLogFolder()
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
REM Define Local Variables
DIM Logs : Set Logs = Nothing
REM Initialize Local Variables
LogFolder = "\\" & OldComputer & "\" & TempFolder & LogFolderName & "\"
Logs = LogFolder & "robocopy.log"
If NOT FSO.FolderExists("\\" & OldComputer & "\" & TempFolder) then
FSO.CreateFolder("\\" & OldComputer & "\" & TempFolder)
End If
If NOT FSO.FolderExists(LogFolder) then
FSO.CreateFolder(LogFolder)
End If
If FSO.FileExists(Logs) then
FSO.DeleteFile(Logs)
End If
REM Cleanup Local Variables
Set FSO = Nothing
Set Logs = Nothing
End Sub
'*******************************************************************************
Sub DetermineOS()
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
IF FSO.FolderExists("\\" & OldComputer & "\c$\users\") then
OldComputerOS = "Windows7"
Else
OldComputerOS = "WindowsXP"
End If
IF FSO.FolderExists("\\" & NewComputer & "\c$\users\") then
NewComputerOS = "Windows7"
Else
NewComputerOS = "WindowsXP"
End If
REM Cleanup Local Variables
Set FSO = Nothing
End Sub
'*******************************************************************************
Sub CopyFilesXP2XP()
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM ExcludeDir : Set ExcludeDir = Nothing
DIM ExcludeFiles : Set ExcludeFiles = Nothing
DIM Logs : Set Logs = Nothing
DIM Parameters : Set Parameters = Nothing
DIM RoboCopy : Set RoboCopy = Nothing
DIM Switches : Set Switches = Nothing
DIM RemoteExec : RemoteExec = RelativePath & "PSTools\PsExec.exe \\" & OldComputer &_
Chr(32) & "-u nash\win2kload -p 2kosload" & Chr(32)
REM Initialize Robocopy Variables
Switches = "/e /eta /r:1 /w:0"
ExcludeDir = "/xd LocalService NetworkService *Links* *temp *TEMPOR~1 *cache"
ExcludeFiles = "/xf ntuser.* *.exd *.nk2 *.srs extend.dat *cache* *.oab index.* {* *.ost UsrClass.* SharePoint*.pst history* *tmp*"
Logs = "/log:" & LogFolder & "robocopy.log"
Parameters = Chr(32) & Switches & Chr(32) & ExcludeDir & Chr(32) & ExcludeFiles
RoboCopy = RemoteExec & NetworkPath & "PSTools\robocopy.exe " & Chr(34) & "c:\Documents and Settings\" & UserName & Chr(34) &_
Chr(32) & Chr(34) & "\\" & NewComputer & "\c$\Documents and Settings\" & UserName & Chr(34) & Parameters
ReturnCode = oShell.Run(RoboCopy, 1, True)
REM Local Memory Cleanup
Set oShell = Nothing
Set Switches = Nothing
Set ExcludeDir = Nothing
Set ExcludeFiles = Nothing
Set Logs = Nothing
Set Parameters = Nothing
Set RemoteExec = Nothing
Set RoboCopy = Nothing
End Sub
'*******************************************************************************
Sub CopyFilesXP2Win7()
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM ExcludeDir : Set ExcludeDir = Nothing
DIM ExcludeFiles : Set ExcludeFiles = Nothing
DIM Logs : Set Logs = Nothing
DIM Parameters : Set Parameters = Nothing
DIM RoboCopy : Set RoboCopy = Nothing
DIM Switches : Set Switches = Nothing
DIM RemoteExec : RemoteExec = RelativePath & "PSTools\PsExec.exe \\" & OldComputer &_
Chr(32) & "-u nash\win2kload -p 2kosload" & Chr(32)
REM Initialize Robocopy Variables
Switches = "/e /eta /r:1 /w:0"
ExcludeDir = "/xd Application* Cookies IETldCache *Links* Local* NetHood NetworkService PrintHood PrivacIE Recent SendTo Start* *temp Templates *TEMPOR~1 Tracing *cache"
ExcludeFiles = "/xf ntuser.* ilent* *.exd *.nk2 *.srs extend.dat *cache* *.oab index.* {* *.ost UsrClass.* SharePoint*.pst history* *tmp*"
Logs = "/log:" & LogFolder & "robocopy.log"
Parameters = Chr(32) & Switches & Chr(32) & ExcludeDir & Chr(32) & ExcludeFiles
RoboCopy = RemoteExec & NetworkPath & "PSTools\robocopy.exe " & Chr(34) & "c:\Documents and Settings\" & UserName & Chr(34) &_
Chr(32) & Chr(34) & "\\" & NewComputer & "\c$\users\" & UserName & Chr(34) & Parameters
ReturnCode = oShell.Run(RoboCopy, 1, True)
REM Local Memory Cleanup
Set oShell = Nothing
Set Switches = Nothing
Set ExcludeDir = Nothing
Set ExcludeFiles = Nothing
Set Logs = Nothing
Set Parameters = Nothing
Set RemoteExec = Nothing
Set RoboCopy = Nothing
End Sub
'*******************************************************************************
Sub CopyFilesWin72Win7()
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM ExcludeDir : Set ExcludeDir = Nothing
DIM ExcludeFiles : Set ExcludeFiles = Nothing
DIM Logs : Set Logs = Nothing
DIM Parameters : Set Parameters = Nothing
DIM RoboCopy : Set RoboCopy = Nothing
DIM Switches : Set Switches = Nothing
DIM RemoteExec : RemoteExec = RelativePath & "PSTools\PsExec.exe \\" & OldComputer &_
Chr(32) & "-u nash\win2kload -p 2kosload" & Chr(32)
REM Initialize Robocopy Variables
Switches = "/e /eta /r:1 /w:0"
ExcludeDir = "/xd LocalService NetworkService *Links* *temp *TEMPOR~1 *cache"
ExcludeFiles = "/xf ntuser.* *.exd *.nk2 *.srs extend.dat *cache* *.oab index.* {* *.ost UsrClass.* SharePoint*.pst history* *tmp*"
Logs = "/log:" & LogFolder & "robocopy.log"
Parameters = Chr(32) & Switches & Chr(32) & ExcludeDir & Chr(32) & ExcludeFiles
RoboCopy = RemoteExec & NetworkPath & "PSTools\robocopy.exe " & Chr(34) & "c:\users\" & UserName & Chr(34) &_
Chr(32) & Chr(34) & "\\" & NewComputer & "\c$\users\" & UserName & Chr(34) & Parameters
ReturnCode = oShell.Run(RoboCopy, 1, True)
REM Local Memory Cleanup
Set oShell = Nothing
Set Switches = Nothing
Set ExcludeDir = Nothing
Set ExcludeFiles = Nothing
Set Logs = Nothing
Set Parameters = Nothing
Set RemoteExec = Nothing
Set RoboCopy = Nothing
End Sub
'*******************************************************************************
Sub VerifyCopy()
If ReturnCode = "0" then
MsgBox("The profile, " & UserName & ", on " & OldComputer & " successfully copied to " & NewComputer & ".")
Else
MsgBox("The profile, " & UserName & ", on " & OldComputer & " failed to copy to " & NewComputer & " due to error " & ReturnCode & ".")
End If
End Sub
'*******************************************************************************
Sub GlobalMemoryCleanup()
Set NewComputer = Nothing
Set OldComputer = Nothing
Set RelativePath = Nothing
Set UserName = Nothing
End Sub