-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathUSMTCapture.vbs
More file actions
316 lines (263 loc) · 12.8 KB
/
USMTCapture.vbs
File metadata and controls
316 lines (263 loc) · 12.8 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
REM ***************************************************************************
REM *** Program: USMTCapture.vbs
REM *** Author: Mick Pletcher
REM *** Created: 23 July 2010
REM *** Edited: 21 March 2011
REM ***
REM *** Description: This script will execute the USMT, creating a MIG file
REM *** located on the selected location, either on the local
REM *** machine, or on the network location. This is intended to
REM *** be used for generating the MIG file for the MDT/SCCM
REM *** imaging process to be included in the build. This was written
REM *** so that this script can be executed from any machine
REM *** which then executes the USMT process locally on the
REM *** target machine. PSTools will need to be downloaded and
REM *** extracted to the USMTLocation, specified below in the
REM *** Global constants. The global constants should be the
REM *** primary changes needed to be made to run this script
REM *** on any machine. The other change that will be needed
REM *** is in the USMTMigrate Subroutine. There are
REM *** additional XML files I have written for the USMT
REM *** process that would need to be removed.
REM ***
REM *** NOTE: To expedite the USMT process, I would suggest
REM *** going to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\
REM *** CurrentVersion\ProfileList and deleting all keys except for
REM *** the following (You can find the key name under
REM *** ProfileImagePath): SystemProfile, LocalService,
REM *** NetworkService, Administrator, and the user profile
REM *** being migrated. This will dramatically speed up the process
REM *** otherwise it will scan each profile 20 times, with a 5
REM *** second delay upon each failure. You need not delete
REM *** the profile directory, as the USMT only scans the
REM *** profiles listed under that registry key.
REM ***
REM *** Script Process:
REM *** 1) Create HTML Display Status Window
REM *** 2) Enter Source, Destination, and Username
REM *** 3) Delete Old USMT folders and Create New USMT Folders
REM *** 4) Determine if the system is x86 or x64
REM *** 5) Perform USMT Migration on Old Machine
REM *** 6) Exit Script if USMT Migration Failed
REM *** 7) Verify USMT
REM *** 8) Cleanup Global Variables
REM ***
REM ***************************************************************************
Option Explicit
REM Define Global Constants
'Used in the query for retrieving the SID
CONST NetDomain = "nash"
' Specifies where to find the USMT executables
CONST USMTLocation = "\\global.gsp\data\special\Deploy\USMT40\"
' Specifies where to write the MIG file locally
CONST USMTLocalStore = "c:\temp\MigData\"
' Specifies where to write the MIG file on the network share
CONST USMTNetworkStore = "\\MDT02\USMT\"
REM Define Global Objects
DIM objIE : Set objIE = CreateObject("InternetExplorer.Application")
REM Define Global Variables
DIM OldComputer : Set OldComputer = Nothing
DIM ReturnCode : ReturnCode = "0"
DIM SID : Set SID = Nothing
DIM UserName : Set UserName = Nothing
DIM USMTOutput : Set USMTOutput = Nothing
DIM USMTSourceCMD : USMTSourceCMD = "0"
DIM USMTDestCMD : USMTDestCMD = "0"
REM Create HTML Display Status Window
CreateDisplayWindow()
REM Enter Source, Destination, and Username
GetComputerInfo()
REM Delete Old USMT folders, if exists, and Create New USMT Folders
CreateUSMTFolders()
REM Determine if the system is x86 or x64
DetermineArchitecture()
REM Retrieve SID from Old Computer
GetSID()
REM Perform USMT Migration on Old Machine
USMTMigrate()
REM Verify the ScanState ran with no errors
VerifyScanState()
REM Cleanup Global Variables
GlobalVariableCleanUp()
'******************************************************************************
'******************************************************************************
Sub CreateDisplayWindow()
REM Define Local Constants
CONST strComputer = "."
REM Define Local Objects
DIM objWMIService : Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
DIM colItems : Set colItems = objWMIService.ExecQuery ("Select PelsWidth,PelsHeight From Win32_DisplayConfiguration")
DIM objItem : Set objItem = Nothing
REM Define Local Variables
DIM intWidth : intWidth = 320
DIM intHeight : intHeight = 240
DIM intScreenWidth : Set intScreenWidth = Nothing
DIM intScreenHeight : Set intScreenHeight = Nothing
For Each objItem in colItems
intScreenWidth = objItem.PelsWidth
intScreenHeight = objItem.PelsHeight
Next
objIE.Navigate "about:blank"
objIE.Toolbar = 0
objIE.StatusBar = 0
objIE.AddressBar = 0
objIE.MenuBar = 0
objIE.Resizable = 0
While objIE.ReadyState <> 4
WScript.Sleep 100
Wend
objIE.Left = (intScreenWidth / 2) - (intWidth / 2)
objIE.Top = (intScreenHeight / 2) - (intHeight / 2)
objIE.Visible = True
REM Cleanup Local Variables
Set colItems = Nothing
Set intScreenWidth = Nothing
Set intScreenHeight = Nothing
Set intWidth = Nothing
Set intHeight = Nothing
Set objItem = Nothing
Set objWMIService = Nothing
End Sub
'******************************************************************************
Sub GetComputerInfo()
OldComputer = InputBox( "Enter the old computer name:" )
UserName = InputBox( "Enter the username:" )
USMTOutput = MsgBox("Output USMT to Network Location?", 4)
If USMTOutput = 6 then
USMTOutput = USMTNetworkStore & UserName & "\" & OldComputer
Else
USMTOutput = USMTLocalStore & UserName & "\" & OldComputer
End If
objIE.Document.WriteLn "<FONT SIZE=8>USMT migration of " & UserName & " from " & OldComputer & " to " & USMTOutput &_
Chr(32) & "</FONT><BR><BR><BR>"
End Sub
'******************************************************************************
Sub CreateUSMTFolders()
On Error Resume Next
REM Define Local Objects
DIM FSO : SET FSO = CreateObject("Scripting.FileSystemObject")
DIM oShell : Set oShell = WScript.CreateObject("WScript.Shell")
REM Define Local Variables
DIM CreateFolder : CreateFolder = "cmd.exe /c md" & Chr(32) & USMTOutput
objIE.Document.WriteLn "Creating USMT Folders....."
REM Create the USMT folders if they do not exist
If NOT FSO.FolderExists(USMTOutput) then
oShell.Run CreateFolder, 7, True
End If
REM Cleanup Local Variables
Set FSO = Nothing
Set CreateFolder = Nothing
Set oShell = Nothing
End Sub
'******************************************************************************
Sub DetermineArchitecture()
REM Define Local Objects
DIM FSO : SET FSO = CreateObject("Scripting.FileSystemObject")
DIM objWMIService : Set objWMIService = Nothing
DIM objWMIServiceSet : Set objWMIServiceSet = Nothing
DIM colOperatingSystems : Set colOperatingSystems = Nothing
DIM objOperatingSystem : Set objOperatingSystem = Nothing
REM Define Local Variables
DIM x86RUNPATH : x86RUNPATH = USMTLocation & "x86"
DIM x64RUNPATH : x64RUNPATH = USMTLocation & "x64"
DIM OSSourceType : OSSourceType = "\\" & OldComputer & "\c$\Program Files (x86)"
DIM msgSource : Set msgSource = Nothing
Set objWMIService = GetObject("winmgmts:\\" & OldComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
msgSource = objOperatingSystem.Caption
Next
objIE.Document.WriteLn "Determining Source Architecture....."
If FSO.FolderExists(OSSourceType) Then
USMTSourceCMD = x64RUNPATH
else
USMTSourceCMD = x86RUNPATH
End IF
If NOT USMTSourceCMD = "0" then
objIE.Document.WriteLn "Success" & "<BR>"
else
objIE.Document.WriteLn "Failure(" & ReturnCode & ")" & "<BR>"
End If
objIE.Document.WriteLn " Source: " & msgSource &_
Chr(32) & Right(USMTSourceCMD,3) & "<BR><BR>"
REM Cleanup Variables
Set colOperatingSystems = Nothing
Set FSO = Nothing
Set msgSource = Nothing
Set x86RUNPATH = Nothing
Set x64RUNPATH = Nothing
Set objWMIService = Nothing
Set objWMIServiceSet = Nothing
Set OSSourceType = Nothing
Set objOperatingSystem = Nothing
End Sub
'******************************************************************************
Sub GetSID()
REM Define Local Objects
DIM objWMIService : Set objWMIService = GetObject("winmgmts:\\" & OldComputer & "\root\cimv2")
DIM objAccount : Set objAccount = Nothing
' Set objAccount = objWMIService.Get _
' ("Win32_UserAccount.Name=" & Chr(39) & UserName & Chr(39) & ",Domain='nash'")
Set objAccount = objWMIService.Get _
("Win32_UserAccount.Name=" & Chr(39) & UserName & Chr(39) & ",Domain=" & Chr(39) & NetDomain & Chr(39))
SID = objAccount.SID
REM Local Variable Cleanup
Set objAccount = Nothing
Set objWMIService = Nothing
End Sub
'******************************************************************************
Sub USMTMigrate()
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM Debug : Debug = "13"
DIM IgnoreProfs : IgnoreProfs = "cmd.exe /c Set MIG_IGNORE_PROFILE_MISSING=1"
DIM TMP : TMP = "c:\Temp"
DIM MigData : MigData = TMP & "\MigData"
DIM LOGPATH : LOGPATH = MigData & "\" & UserName
DIM RemoteExec : RemoteExec = USMTLocation & "PSTools\PsExec.exe \\" & OldComputer &_
Chr(32) & "-s" & Chr(32)
DIM USMT : USMT = RemoteExec & USMTSourceCMD & "\scanstate.exe " & USMTOutput & Chr(32) & "/v:" & Debug & Chr(32) & "/i:" &_
USMTSourceCMD & "\Migapp.xml" & Chr(32) & "/i:" & USMTSourceCMD & "\MigDocs.xml" & Chr(32) & "/i:" &_
USMTSourceCMD & "\miguser.xml" & Chr(32) & "/i:" & USMTSourceCMD & "\MigExclude.xml" & Chr(32) &_
"/progress:" & LOGPATH & "\ScanStateProg.log" & Chr(32) & "/l:" & LOGPATH & "\ScanState.log" &_
Chr(32) & "/ui:" & SID & Chr(32) & "/ue:*\* /c /vsc"
objIE.Document.WriteLn "Executing Scanstate on " & OldComputer & "....."
ReturnCode = oShell.Run(IgnoreProfs, 7, True)
ReturnCode = oShell.Run(USMT, 7, True)
If ReturnCode = "0" Then
objIE.Document.WriteLn "Success" & "<BR><BR>"
else
objIE.Document.WriteLn "Failure(" & ReturnCode & ")" & "<BR><BR>"
End If
REM Cleanup Variables
Set Debug = Nothing
SET IgnoreProfs = Nothing
SET oShell = Nothing
SET TMP = Nothing
SET MigData = Nothing
SET LOGPATH = Nothing
Set RemoteExec = Nothing
Set USMT = Nothing
End Sub
'******************************************************************************
Sub VerifyScanState()
If NOT ReturnCode = "0" then
MsgBox("The data migration on " & OldComputer & " failed due to error" & ReturnCode &_
". Please check the log file located at & \\" & OldComputer & "\c$\Temp\MigData\ScanLog.log.")
GlobalVariableCleanUp()
WScript.Quit
Else
Set ReturnCode = Nothing
End If
End Sub
'******************************************************************************
Sub GlobalVariableCleanUp()
Set OldComputer = Nothing
Set objIE = Nothing
Set ReturnCode = Nothing
Set UserName = Nothing
Set USMTOutput = Nothing
Set USMTSourceCMD = Nothing
Set USMTDestCMD = Nothing
End Sub