USMT Test Environment Setup Script

I’ve been working hard lately on the various USMT migration scenarios using SCCM with hardlinking and State Migration Points. One of the frustrating things during this process is creating ‘user state’. Creating user state for your test migrations is important as you need to ensure that your testing covers the regular places that users will store files, and that USMT is doing it’s job and migrating this data.

The frustrating part is the time it takes to create some reasonable user state. You want to add files and folders to users profiles across multiple locations. I’ve written a VB Script to automate this process. The script will work for either Windows XP or Windows 7 environments. It basically creates a bunch of files and folders in the logged in users Desktop, My Documents, My Pictures and App Data directories.

''    USMT Environment Setup    ''
'' Created by Matt Shadbolt ''
Option Explicit
'Declare Variables
Dim objFSO, objFolder, strDirectory
Dim objNetwork
Dim profilePath
Dim x
Dim filetxt, getname, path
Dim LocalAppDataPath, RoamingAppDataPath
Dim MyDocuments, MyDesktop, MyPictures
'Set Variables
x = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
profilePath = UserInput( "Is this for XP or WIN7?")
' Check if XP or Windows 7
If profilePath = "XP" Then
profilePath = "C:\Documents and Settings\"
LocalAppDataPath = "\Local Settings\Application Data\"
RoamingAppDataPath = "\Application Data\"
MyDocuments = "My Documents"
MyDesktop = "Desktop"
MyPictures = "My Documents\My Pictures"
ElseIf profilePath = "WIN7" Then
profilePath = "C:\Users\"
LocalAppDataPath = "\AppData\Local\"
RoamingAppDataPath = "\AppData\Roaming\"
MyDocuments = "Documents"
MyDesktop = "Desktop"
MyPictures = "Pictures"
Else
MsgBox "You need to enter either XP or WIN7 (CaSe SeNsItIvE) "
Wscript.Quit
End If
' Desktop Folders
While x < 10
strDirectory = profilePath & objNetwork.Username & "\" & MyDesktop & "\DesktopFolder" & x
Set objFolder = objFSO.CreateFolder(strDirectory)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "TextFile" & x & ".txt", True)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "WordDoc" & x & ".doc", True)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "Shortcut" & x & ".lnk", True)
x = x + 1
Wend
x = 0
' My Documents
While x < 10
strDirectory = profilePath & objNetwork.Username & "\" & MyDocuments & "\DocumentsFolder" & x
Set objFolder = objFSO.CreateFolder(strDirectory)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "WordDoc" & x & ".doc", True)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "WordDoc1" & x & ".doc", True)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "WordDoc2" & x & ".doc", True)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "WordDoc3" & x & ".doc", True)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "WordDoc4" & x & ".doc", True)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "WordDoc5" & x & ".doc", True)
x = x + 1
Wend
x = 0
' My Pictures
While x < 10
strDirectory = profilePath & objNetwork.Username & "\" & MyPictures & "\PicturesFolder" & x
Set objFolder = objFSO.CreateFolder(strDirectory)
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "Picture" & x & ".jpg", True)
x = x + 1
Wend
x = 0
' AppDatat\Local
strDirectory = profilePath & objNetwork.Username & LocalAppDataPath & "SomeAppData"
Set objFolder = objFSO.CreateFolder(strDirectory)
While x < 10
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "AppDataFile" & x & ".appData", True)
x = x + 1
Wend
x = 0
' AppData\Roaming
strDirectory = profilePath & objNetwork.Username & RoamingAppDataPath & "SomeAppData"
Set objFolder = objFSO.CreateFolder(strDirectory)
While x < 10
Set filetxt = objFSO.CreateTextFile(strDirectory &"\" & "AppDataFile" & x & ".appData", True)
x = x + 1
Wend
x = 0
MsgBox "Success!"
''' Functions '''
'Input OS type
Function UserInput( myPrompt )
If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
WScript.StdOut.Write myPrompt & " "
UserInput = WScript.StdIn.ReadLine
Else
UserInput = InputBox( myPrompt )
End If
End Function
 
Matt Shadbolt