Your company's ad could live here and reach over 50,000 people a month!

Share This Post

Community solutions: Migrate user state from XP to Windows 7 during Windows 7 Migration project

From James Avery:

Problem

My goal was to allow a third party company to Migrate user state from XP to Windows 7 during our Windows 7 Migration project. Doing this tasks through SCCM console isn’t worth it when the 3rd party staff will be changing during the project.

I needed to have the Source Computer and the Destination computer do the following when the "Create Computer Association" button is pushed.

  1. Add Source and Destination computer to the Computer Association in SCCM OSD
  2. Add Source Computer to the Collection I called Scanstate
  3. Add Destination Computer to the Collection I called Loadstate

 

Solution

Here’s the code for everyone!!

Download code: Migrate user state from XP to Windows 7 during Windows 7 Migration project (3.1k)

 

<html>
<head>
<title>USMT | Windows 7 Image</title>
<script language="VBScript">Window.ResizeTo 913,810</script>
<script language="VBScript">Window.MoveTo ((Screen.AvailWidth -913) / 2), 10</script>
<HTA:APPLICATION
ID="objOSDReg"
APPLICATIONNAME="OSD_Registration"
SINGLEINSTANCE="yes"
BORDER="thin"
ICON="Deploy.ico"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="yes"
NAVIGABLE="yes"
>
</head>
<SCRIPT LANGUAGE="VBScript">
‘Set Variables: Site Server, Username and Password
‘Server = "XXXXXXXXX"
‘userName = "XXXXXXXXX"
‘userPassword = "XXXXXXXXX"
Dim computera, computerb, ResIDA, ResIDB, sccmserver, server, userid, userName, pswd, userpassword
Dim strSourceResourceID, strDestinationResourceID, strCaptureCollectionID, strRestoreCollectionID, objSMS
Sub AssociateCompAandCompB
‘Server = document.getElementById("sccmserver").value
‘username = document.getElementById("userid").value
‘userpassword = document.getElementById("pswd").value
strcomputera = document.getElementById("computera").value
strcomputerb = document.getElementById("computerb").value
strCaptureCollectionID = "OKE0033E"
strRestoreCollectionID = "OKE0033D"
‘ connection to SCCM server
Set objSMS = Connect(Server, userName, userpassword)
ResIDA = GetResourceIDFromName (objSMS, strcomputera)
ResIDB = GetResourceIDFromNameB (objSMS, strcomputerb)
‘AddtoCollection
If (ResIDA <> 0) And (ResIDB <> 0) Then
AssociateComputer objSMS, ResIDA, ResIDB
AddtoCollection strcomputerA, ResIDA, strCaptureCollectionID
AddtoCollection strcomputerb, ResIDB, strRestoreCollectionID
Else
General_OnClick()
End If
End Sub
‘ ——————————————————————————————————————-
‘ Associate Computers in SCCM Computer Association
‘ ——————————————————————————————————————-
Sub AssociateComputer(objSMS, referenceComputerResourceId, destinationComputerResourceId)
Dim stateMigrationClass
Dim inParams
Dim outParams
‘On Error Resume Next
‘ Get the state migration class.
Set stateMigrationClass = objSMS.Get("SMS_StateMigration")
‘ Set up the parameters.
Set inParams = _
stateMigrationClass.Methods_("AddAssociation").InParameters.SpawnInstance_
inParams.SourceClientResourceID = referenceComputerResourceId
inParams.RestoreClientResourceID = destinationComputerResourceId
‘ Call the method
Set outParams = objSMS.ExecMethod( "SMS_StateMigration","AddAssociation",inParams)
‘ MsgBox Err
if Err.number <> 0 Then
MsgBox "Failed to create a Computer Association, please try again or contact the Windows Deployment Team Lead"
Exit Sub
Else
General_OnClick()
End If
End Sub
‘ ——————————————————————————————————————-
‘AddtoCollection(name, ResourceID, collectionID)
‘ ——————————————————————————————————————-
Sub AddtoCollection(name, ResourceID, collectionID)
‘Sub AddtoCollection(connection, referenceComputerResourceId, destinationComputerResourceId)
‘Dim instColl
‘Dim instDirectRule
‘if one exists create a collection rule
Set instColl = objSMS.Get("SMS_Collection.CollectionID="&"""" & collectionID & """")
Set instDirectRule = objSMS.Get("SMS_CollectionRuleDirect").SpawnInstance_ ()
instDirectRule.ResourceClassName = "SMS_R_System"
instDirectRule.ResourceID = ResourceID
instDirectRule.RuleName = name & " – " & ResourceID
instColl.AddMembershipRule instDirectRule , SMSContext
instColl.RequestRefresh False
‘ log name & " Added to " & Instcoll.Name
‘ wscript.echo(name & " Added to " & Instcoll.Name)
MsgBox (name & " Added to " & Instcoll.Name)
‘ MsgBox Err
if Err.number <> 0 Then
MsgBox "Failed to create a Computer Association, please try again or contact the Windows Deployment Team Lead"
Exit Sub
Else
General_OnClick()
End If
End Sub
‘ ——————————————————————————————————————-
‘ Utility function to search for the site code
‘ ——————————————————————————————————————-
Function Connect(server, userName, userPassword)
‘On Error Resume Next
Dim net
Dim localConnection
Dim swbemLocator
Dim swbemServices
Dim providerLoc
Dim location
Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")’
swbemLocator.Security_.AuthenticationLevel = 6 ‘Packet Privacy.
‘ If the server is local, don’t supply credentials.
‘ Set net = CreateObject("WScript.NetWork")
‘ If UCase(net.ComputerName) = UCase(server) Then
‘ localConnection = True
‘ userName = ""
‘ userPassword = ""
‘ server = "."
‘ End If
‘ Connect to the server.
Set swbemServices= swbemLocator.ConnectServer _
(server, "root\sms",userName,userPassword)
If Err.Number<>0 Then
‘ Wscript.Echo "Couldn’t connect: " + Err.Description
Connect = Null
Exit Function
End If
‘ Determine where the provider is and connect.
Set providerLoc = swbemServices.InstancesOf("SMS_ProviderLocation")
For Each location In providerLoc
If location.ProviderForLocalSite = True Then
Set swbemServices = swbemLocator.ConnectServer _
(location.Machine, "root\sms\site_" + _
location.SiteCode,userName,userPassword)
If Err.Number<>0 Then
‘ Wscript.Echo "Couldn’t connect:" + Err.Description
Connect = Null
Exit Function
Else
‘Wscript.Echo "Yay, we connected!!"
End If
Set Connect = swbemServices
Exit Function
End If
Next
Set Connect = null ‘ Failed to connect.
End Function
‘ ——————————————————————————————————————-
‘ GetResourceID From Name A
‘ ——————————————————————————————————————-
Function GetResourceIDFromName(objSMS, strcomputera)
‘On Error Resume Next
‘ Build Query string.
query = "SELECT ResourceId FROM SMS_R_System WHERE NetbiosName = """ & strcomputera & """"
‘ Execute the query
‘Set result = connection.ExecQuery(query)
Set result = objSMS.ExecQuery(query)
If Err then
CheckError
‘MsgBox "error on a"
Exit Function
End If
‘ Walk through the elements of the enumerator.
‘ Assume there will only be 1 computer with the requested name, if any.
resourceID = 0 ‘ Assume the worst
For each r in result
GetResourceIDFromName = r.ResourceID
‘MsgBox r.resourceID
Next
End Function
‘ ——————————————————————————————————————-
‘ GetResourceID From Name B
‘ ——————————————————————————————————————-
Function GetResourceIDFromNameB(objSMS, strcomputerb)
On Error Resume Next
‘ Build Query string.
query = "SELECT ResourceId FROM SMS_R_System WHERE NetbiosName = """ & strComputerB & """"
‘ Execute the query
Set result = objSMS.ExecQuery(query)
‘Set result = connection.ExecQuery(query)
If Err then
CheckError
Exit Function
End If
‘ Walk through the elements of the enumerator.
‘ Assume there will only be 1 computer with the requested name, if any.
resourceID = 0 ‘ Assume the worst
For each b in result
GetResourceIDFromNameB = b.ResourceID
‘MsgBox b.resourceID
Next
End Function
‘ ——————————————————————————————————————-
‘ ——————————————————————————————————————-
Sub General_OnClick()
strHtm = "<table class=""tbl"">"
strHtm = strHtm & "<tr><td>_________________________</td><td>_________________</td></tr>"
strHtm = strHtm & "<tr><td>Source Computer </td><td>" & document.getElementById("computera").value & "</td></tr><tr></tr>"
strHtm = strHtm & "<tr><td>_________________________</td><td>_________________</td></tr>"
strHtm = strHtm & "<tr><td>Destination Computer </td><td>" & document.getElementById("computerb").value & "</td></tr>"
strHtm = strHtm & "</table>"
‘Next
dataarea.innerhtml = strHtm
End Sub
</SCRIPT>
<!– ——————————————————————————————————————- –>
<!– HTML Starts –>
<!– ——————————————————————————————————————- –>
<body style="font-family: Arial; background-image: url(‘Win7_wallpaper-blue2.jpg’); background-repeat: no-repeat; background-color: black; color: white;">
<!–OSD Registration Header–>
<table style="text-align: left; width: 100px;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td><big><big><big><big><span>&nbsp;&nbsp;&nbsp;&nbsp;OSD</span></big></big></big></big></td>
<td style="text-align: right;"><span>&nbsp;powered<br>&nbsp;by</span></td>
<td><span><img style="width: 301px; height: 64px;" alt="System Center" src="file:logo-system-center.gif"></span></td>
</tr>
</tbody>
</table>
<!–Line Break–>
<hr style="color:#00B2EE">
<!–Deployment Scenario Selection–>
<table align="center" width="90%">
<tr><td>
<h3>&nbsp;&nbsp;&nbsp;&nbsp;Server Connection</h3>
<!– HTA Text Input Box for Server–>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Server: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="sccmserver" size="18"><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserName: &nbsp; <input type="text" id="userid" size="18"><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password: &nbsp;&nbsp; <input type="password" id="pswd" size="18"></p>
</td></tr>
</table>
<table align="center" width="90%">
<tr><td> <BR>
<h3>&nbsp;&nbsp;&nbsp;&nbsp;Computer Association</h3>
<!– HTA Text Input Box for Computer A (Source)–><!– HTA Text Input Box for Computer B (Destination)–>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Source Computer: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="ComputerA" size="15"><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Destination Computer: &nbsp;&nbsp;<input type="text" id="ComputerB" size="15"></p>
<!– A – AssociateCompAandCompB –> <!– Resets Page –>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id=runbutton type="button" value="Create Computer Association" name="run_button" onClick="AssociateCompAandCompB">
&nbsp;&nbsp;&nbsp;<input type="button" value="Reset Page" onClick="window.location.reload()"></p><BR>
</td></tr>
</table>
<!– Display Data on HTA screen –>
<table align="center" width="85%">
<tr><td>
<!–Line Break–>
<div style="margin: 25px 100px 0px 0px; background-color: transparent; padding: 10px;">
<div> <hr style="color:#00B2EE">
<div> <h4>Computer Association Output<h4>
<div id="dataarea"></div>
</div>
</td></tr>
</table>
<br><br>
<!–Version #–>
<small style="color: rgb(100,100,100)">&nbsp;&nbsp;#1v1.1</small>
<table align="center" valign="center" width="100%">
<tr><big><big><span id="msgTXT"> </span></big></big><br></tr>
<tr style="color:red;"><big><big><span id="msgERR"> </span></big></big><br></tr>
</table>
</body>
</html>

Download code:  Migrate user state from XP to Windows 7 during Windows 7 Migration project (3.1k)

 

Original post: VBScript and HTA for SCCM 07

Share This Post

A community professional, keynoter, and evangelist who has driven social media and marketing strategies, editorial successes, delivered customer successes and built some of the largest and longest-running online communities. Rod has created, managed and grown small, medium, and mega-sized conferences; run entire editorial teams to deliver record traffic and market leadership; as product manager, directed the success of hundreds of product releases; supported sales and marketing to ensure customer success; developed, run and sold businesses; written thousands of technical articles, white papers, case studies, and technical documentation; hosted and delivered hundreds of attendance shattering webinars and virtual tradeshows; and delivered keynote speeches and sessions at a wide variety of events including conferences, webinars, events, and user groups.

Leave a Reply