<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx</link><description>Hi Rob here again. I recently had a customer that needed the functionality of MoveUser.exe from the Windows 2000 Resource Kit available in Windows Vista. The customer had quite a few Windows Vista machines that were not joined to the domain but were now</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3325864</link><pubDate>Sun, 18 Apr 2010 02:30:13 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3325864</guid><dc:creator>hxgc</dc:creator><description>&lt;p&gt;Hi:&lt;/p&gt;
&lt;p&gt;I have modified the script to let move user from domain to local. Also assumed that only one domain involved, so don't have to change script for domain. &lt;/p&gt;
&lt;p&gt;Tested working fine, feel free to report any errors&lt;/p&gt;
&lt;p&gt;'=========================================================================== &lt;/p&gt;
&lt;p&gt;' &amp;nbsp;MoveUser.vbs&lt;/p&gt;
&lt;p&gt;' &amp;nbsp;Rob Greene of Technet created the original script&lt;/p&gt;
&lt;p&gt;' &amp;nbsp;Ron Williams expanded it to have similar functionality to the previous Moveuser.exe &lt;/p&gt;
&lt;p&gt;' &amp;nbsp;Harvey Chen modified it so it can move users from and to domain and &lt;/p&gt;
&lt;p&gt;' &amp;nbsp;removed hard cocded domain veriable, instead look at command line to find &amp;nbsp;&lt;/p&gt;
&lt;p&gt;' &amp;nbsp;domain/user format and use the domain part.&lt;/p&gt;
&lt;p&gt;'=========================================================================== &lt;/p&gt;
&lt;p&gt;Option Explicit &lt;/p&gt;
&lt;p&gt;Dim strComputer, strSourceAcct, strSourceAcctDomain, strTargetAcct &lt;/p&gt;
&lt;p&gt;Dim strTargetAcctDomain, strTargetAcctSID, objComputer, objOs &lt;/p&gt;
&lt;p&gt;DIM objProfile, objCommand, objRecordSet, objConnection, objWMIService&lt;/p&gt;
&lt;p&gt;DIM dtStart, colProfiles, oSID, oUsr, strDomain, objSID &lt;/p&gt;
&lt;p&gt;DIM Revision, IssueAuthorities(11), strSDDL, subAuthorities&lt;/p&gt;
&lt;p&gt;DIM strDomAcctLength, strCompName, strSlashPos, strContinue&lt;/p&gt;
&lt;p&gt;DIM strDomainAcct, strLocalAcct, strLocalAcctLength, strArg3&lt;/p&gt;
&lt;p&gt;DIM strKeepuser, strArg4, colOperatingSystems, strSrcDom, strOSVer&lt;/p&gt;
&lt;p&gt;Dim strTargetAcctCommand, strSourceAcctCommand, strTargetAcctExist &lt;/p&gt;
&lt;p&gt;Dim strSourceAcctLength, strTargetAcctLength, strSourceAcctExist&lt;/p&gt;
&lt;p&gt;CONST ADS_SCOPE_SUBTREE=2 &lt;/p&gt;
&lt;p&gt;'If arguments are not two then promt for Syntax&lt;/p&gt;
&lt;p&gt;If WScript.Arguments.Count &amp;gt;= 2 Then&lt;/p&gt;
&lt;p&gt;	strSourceAcctCommand = WScript.Arguments.Item(0)&lt;/p&gt;
&lt;p&gt;	strTargetAcctCommand = WScript.Arguments.Item(1)&lt;/p&gt;
&lt;p&gt;Else&lt;/p&gt;
&lt;p&gt;	Call Syntax&lt;/p&gt;
&lt;p&gt;End If&lt;/p&gt;
&lt;p&gt;'Process arg 1 for source profile&lt;/p&gt;
&lt;p&gt;If InStr (strSourceAcctCommand, &amp;quot;\&amp;quot;) = 0 Then&lt;/p&gt;
&lt;p&gt;	Set strCompName = WScript.CreateObject(&amp;quot;WScript.Network&amp;quot;)&lt;/p&gt;
&lt;p&gt;	strSourceAcctDomain = strCompName.ComputerName&lt;/p&gt;
&lt;p&gt;	strComputer = &amp;quot;.&amp;quot;&lt;/p&gt;
&lt;p&gt;	strSourceAcct = strSourceAcctCommand&lt;/p&gt;
&lt;p&gt;Else&lt;/p&gt;
&lt;p&gt;	strSourceAcctLength = Len(strSourceAcctCommand)&lt;/p&gt;
&lt;p&gt;	strSlashPos = InStr (strSourceAcctCommand, &amp;quot;\&amp;quot;)&lt;/p&gt;
&lt;p&gt;	strSourceAcct = Right(strSourceAcctCommand,strSourceAcctLength - strSlashPos)&lt;/p&gt;
&lt;p&gt;	strSourceAcctDomain = Left(strSourceAcctCommand,strSlashPos - 1)&lt;/p&gt;
&lt;p&gt;	strDomain = &amp;quot;dc=&amp;quot; &amp;amp; Left(strSourceAcctCommand,strSlashPos - 1) &amp;amp;&amp;quot;,dc=com&amp;quot;&lt;/p&gt;
&lt;p&gt; End If&lt;/p&gt;
&lt;p&gt;'Process arg 2 for target profile&lt;/p&gt;
&lt;p&gt;If InStr (strTargetAcctCommand, &amp;quot;\&amp;quot;) = 0 Then&lt;/p&gt;
&lt;p&gt;	Set strCompName = WScript.CreateObject(&amp;quot;WScript.Network&amp;quot;)&lt;/p&gt;
&lt;p&gt;	strTargetAcctDomain = strCompName.ComputerName&lt;/p&gt;
&lt;p&gt;	strTargetAcct = strTargetAcctCommand&lt;/p&gt;
&lt;p&gt;	'Call function to get target account SID&lt;/p&gt;
&lt;p&gt;	strTargetAcctSID = LocalAcctSID(strTargetAcct)	&lt;/p&gt;
&lt;p&gt;Else&lt;/p&gt;
&lt;p&gt;	strTargetAcctLength = Len(strTargetAcctCommand)&lt;/p&gt;
&lt;p&gt;	strSlashPos = InStr (strTargetAcctCommand, &amp;quot;\&amp;quot;)&lt;/p&gt;
&lt;p&gt;	strTargetAcct = Right(strTargetAcctCommand,strTargetAcctLength - strSlashPos)&lt;/p&gt;
&lt;p&gt;	strTargetAcctDomain = Left(strTargetAcctCommand,strSlashPos - 1)&lt;/p&gt;
&lt;p&gt;	' Don't know if I can do different domains.&lt;/p&gt;
&lt;p&gt;	If Not strDomain = &amp;quot;&amp;quot; Then &lt;/p&gt;
&lt;p&gt;		If UCase (strTargetAcctDomain) &amp;lt;&amp;gt; UCase (strSourceAcctDomain) Then&lt;/p&gt;
&lt;p&gt;			WScript.Echo &amp;quot;Sorry source domain &amp;quot; &amp;amp; Ucase (strSourceAcctDomain) &amp;amp;_&lt;/p&gt;
&lt;p&gt;		 	&amp;quot; is different then target domain &amp;quot; &amp;amp; UCase (strSourceAcctDomain) &amp;amp;_&lt;/p&gt;
&lt;p&gt;		 	&amp;quot;. Please check your spelling!&amp;quot;&lt;/p&gt;
&lt;p&gt;		 	WScript.Quit&lt;/p&gt;
&lt;p&gt;		Else&lt;/p&gt;
&lt;p&gt;			'Suppose only do it on local computer	&lt;/p&gt;
&lt;p&gt;			strComputer =&amp;quot;.&amp;quot;&lt;/p&gt;
&lt;p&gt;		End If&lt;/p&gt;
&lt;p&gt;	Else &lt;/p&gt;
&lt;p&gt;	strDomain = strTargetAcctDomain&lt;/p&gt;
&lt;p&gt;	End If &amp;nbsp;&lt;/p&gt;
&lt;p&gt;	'Call function to get target account SID&lt;/p&gt;
&lt;p&gt;	strTargetAcctSID = DomainAcctSID (strTargetAcct)&lt;/p&gt;
&lt;p&gt;End If&lt;/p&gt;
&lt;p&gt;'This part is looking the source profile&lt;/p&gt;
&lt;p&gt;Set objWMIService = GetObject(&amp;quot;winmgmts:\\&amp;quot; &amp;amp; strComputer &amp;amp; &amp;quot;\root\cimv2&amp;quot;) &lt;/p&gt;
&lt;p&gt;Set colProfiles = objWMIService.ExecQuery(&amp;quot;Select * from Win32_UserProfile&amp;quot;) &lt;/p&gt;
&lt;p&gt;For Each objProfile in colProfiles &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Set objSID = objWMIService.Get(&amp;quot;Win32_SID.SID='&amp;quot; &amp;amp; objProfile.SID &amp;amp;&amp;quot;'&amp;quot;) &lt;/p&gt;
&lt;p&gt;	' &amp;nbsp; &amp;nbsp;Testing to verify that the current profile handle is for &lt;/p&gt;
&lt;p&gt;	' &amp;nbsp; &amp;nbsp;the Source Account that we want to move to the domain user. &lt;/p&gt;
&lt;p&gt;	If UCase(objsid.referencedDomainName + &amp;quot;\&amp;quot; + objsid.AccountName)= _ &amp;nbsp;&lt;/p&gt;
&lt;p&gt;	UCase(strSourceAcctDomain + &amp;quot;\&amp;quot; + strSourceAcct) Then &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp;' Making sure that the source profile is currently not in use. &amp;nbsp;If it is we will bail out. &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;strSourceAcctExist = &amp;quot;Yes&amp;quot;&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If objProfile.RefCount &amp;lt; 1 Then &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;strContinue = MsgBox(&amp;quot;Do you want to move Profile form: &amp;nbsp;&amp;quot; &amp;amp; vbNewLine &amp;amp; UCase (strSourceAcctDomain) + &amp;quot;\&amp;quot; &amp;amp; _&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;UCase (strSourceAcct) &amp;amp; vbNewLine &amp;amp; &amp;quot; to: &amp;quot; + UCase (strTargetAcctDomain) &amp;amp; &amp;quot;\&amp;quot; &amp;amp; UCase (strTargetAcct) &amp;amp; &amp;quot;?&amp;quot;, _&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;vbYesNo &amp;amp; vbQuestion, &amp;quot;Move This Profile?&amp;quot;) &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If strContinue = 6 Then &amp;nbsp; '6=Yes, Move the Profile. &lt;/p&gt;
&lt;p&gt;					' ChangeOwner method requires the String SID of Target Account and a Flag setting &lt;/p&gt;
&lt;p&gt;					' Flag 1 = Change ownership of the source profile to target account even if the target account &amp;nbsp;already has a profile on the system. &lt;/p&gt;
&lt;p&gt;					' Flag 2 = Delete the target account Profile and change ownership of the source user account profile to the target account. &lt;/p&gt;
&lt;p&gt;					' To use the ChangeOwner method, both the source and target account profiles (If it exists) must not be loaded. &lt;/p&gt;
&lt;p&gt;					ObjProfile.ChangeOwner strTargetAcctSID,1 &lt;/p&gt;
&lt;p&gt;					WScript.Echo &amp;quot;Congratulations!&amp;quot; &amp;amp; vbNewLine &amp;amp; &amp;quot;User Profile is moved from: &amp;quot;&amp;amp; vbnewline &amp;amp; UCase (strSourceAcctDomain) + &amp;quot;\&amp;quot; &amp;amp; _&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;UCase (strSourceAcct) &amp;amp; vbNewLine &amp;amp; &amp;quot; to: &amp;quot; &amp;amp; UCase (strTargetAcctDomain) &amp;amp; &amp;quot;\&amp;quot; &amp;amp; UCase (strTargetAcct) &amp;amp; _&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vbNewLine &amp;amp; &amp;quot;Process Complete.&amp;quot;&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ElseIf strContinue = 7 Then &amp;nbsp;'7=No, Cancel the move. &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Wscript.Quit&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Else &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Wscript.Quit&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; Else &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Wscript.echo &amp;quot;Could not move the users profile, because &amp;quot; &amp;amp; _&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;UCase (strSourceAcctDomain) + &amp;quot;\&amp;quot; &amp;amp; UCase (strSourceAcct) &amp;amp; &amp;quot; profile is currently loaded&amp;quot; &lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; 	End If &lt;/p&gt;
&lt;p&gt;	End If &lt;/p&gt;
&lt;p&gt;Next &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;If strSourceAcctExist &amp;lt;&amp;gt; &amp;quot;Yes&amp;quot; Then &lt;/p&gt;
&lt;p&gt;	WScript.Echo &amp;quot;Please check source account! Coundn't find &amp;quot; &amp;amp; _&lt;/p&gt;
&lt;p&gt;	 UCase (strSourceAcctDomain) &amp;amp; &amp;quot;\&amp;quot; &amp;amp; UCase (strSourceAcct)&lt;/p&gt;
&lt;p&gt;End If &lt;/p&gt;
&lt;p&gt;Sub Init_IssueAuthorities( ) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;'DIM IssueAuthorities(11) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(0) = &amp;quot;-0-0&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(1) = &amp;quot;-1-0&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(2) = &amp;quot;-2-0&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(3) = &amp;quot;-3-0&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(4) = &amp;quot;-4&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(5) = &amp;quot;-5&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(6) = &amp;quot;-?&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(7) = &amp;quot;-?&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(8) = &amp;quot;-?&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueAuthorities(9) = &amp;quot;-?&amp;quot; &lt;/p&gt;
&lt;p&gt;end sub &lt;/p&gt;
&lt;p&gt;Sub Syntax&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Wscript.Echo &amp;quot;Usage: Moveuser.vbs FromUser ToUser&amp;quot; _&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;amp; VBNewLine _&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;amp; VBNewLine _&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;amp; vbNewLine &amp;amp; &amp;quot;Sample 1: Moveuser.vbs Fred Domain\Smithf&amp;quot; _&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;amp; vbNewLine &amp;amp; &amp;quot;Sample 2: Moveuser.vbs Domain\John JaneDow&amp;quot; _&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;amp; vbNewLine &amp;amp; &amp;quot;There should be no SPACE in account names!&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Wscript.Quit&lt;/p&gt;
&lt;p&gt;End Sub&lt;/p&gt;
&lt;p&gt;Function DomainAcctSID (strAcct)&lt;/p&gt;
&lt;p&gt;Dim strAcctSID, strLDAPQuery&lt;/p&gt;
&lt;p&gt;strAcctSID=&amp;quot;&amp;quot; &lt;/p&gt;
&lt;p&gt;Set objConnection = CreateObject(&amp;quot;ADODB.Connection&amp;quot;) &lt;/p&gt;
&lt;p&gt;objConnection.Provider = &amp;quot;ADsDSOObject&amp;quot;&lt;/p&gt;
&lt;p&gt;objConnection.Open &amp;quot;Active Directory Provider&amp;quot;&lt;/p&gt;
&lt;p&gt;Set objCommand = CreateObject(&amp;quot;ADODB.Command&amp;quot;) &lt;/p&gt;
&lt;p&gt;objCommand.ActiveConnection = objConnection &lt;/p&gt;
&lt;p&gt;strLDAPQuery = &amp;quot;SELECT AdsPath, cn FROM 'LDAP://&amp;quot; + strDomain + &amp;quot;' WHERE objectCategory='user'&amp;quot; &amp;amp; _ &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;quot; And sAMAccountName='&amp;quot; + strAcct + &amp;quot;'&amp;quot;&lt;/p&gt;
&lt;p&gt;objcommand.Properties(&amp;quot;searchscope&amp;quot;) = ADS_SCOPE_SUBTREE&lt;/p&gt;
&lt;p&gt;objCommand.CommandText = strLDAPQuery &lt;/p&gt;
&lt;p&gt;Set objRecordSet = objCommand.Execute &lt;/p&gt;
&lt;p&gt;If objRecordset.RecordCount = 0 Then &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WScript.Echo &amp;quot;Please check your target account! &amp;quot; &amp;amp; UCase (strAcct) &amp;amp; _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;quot; does not exist on &amp;quot; &amp;amp; UCase (strDomain) &amp;amp; &amp;quot;.&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WScript.Quit&lt;/p&gt;
&lt;p&gt;ElseIf objRecordset.RecordCount &amp;gt; 1 Then &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WScript.Echo &amp;quot;There is more than one account with the same sAMAccountName&amp;quot; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WScript.Quit&lt;/p&gt;
&lt;p&gt;Else &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;objRecordSet.MoveFirst &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Do Until objRecordSet.EOF &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Set Ousr = GetObject(objRecordSet.Fields(&amp;quot;AdsPath&amp;quot;).Value) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;strAcctSID = SDDL_SID(oUsr.Get(&amp;quot;objectSID&amp;quot;)) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;objRecordSet.MoveNext &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Loop &lt;/p&gt;
&lt;p&gt;objConnection.Close &lt;/p&gt;
&lt;p&gt;End If&lt;/p&gt;
&lt;p&gt;DomainAcctSID = strAcctSID&lt;/p&gt;
&lt;p&gt;End Function &lt;/p&gt;
&lt;p&gt;function SDDL_SID ( oSID ) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;DIM Revision, SubAuthorities, strSDDL, IssueIndex, index, i, k, p2, subtotal &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;DIM j, dblSubAuth &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt;' First byte is the revision value &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Revision = &amp;quot;1-5&amp;quot;&lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt;' Second byte is the number of sub authorities in the &lt;/p&gt;
&lt;p&gt;' SID &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;SubAuthorities = CInt(ascb(midb(oSID,2,1))) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;strSDDL = &amp;quot;S-&amp;quot; &amp;amp; Revision &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IssueIndex = CInt(ascb(midb(oSID,8,1))) &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt;' BYtes 2 - 8 are the issuing authority structure &lt;/p&gt;
&lt;p&gt;' Currently these values are in the form: &lt;/p&gt;
&lt;p&gt;' { 0, 0, 0, 0, 0, X} &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt;' We use this fact to retrieve byte number 8 as the index &lt;/p&gt;
&lt;p&gt;' then look up the authorities for an array of values &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;strSDDL = strSDDL &amp;amp; IssueAuthorities(IssueIndex) &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt;' The sub authorities start at byte number 9. The are 4 bytes long and &lt;/p&gt;
&lt;p&gt;' the number of them is stored in the Sub Authorities variable. &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;index = 9 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;i = index &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;for k = 1 to SubAuthorities &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Very simple formula, the sub authorities are stored in the &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' following order: &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Byte Index Starting Bit &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Byte 0 - Index 0 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Byte 1 - Index + 1 7 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Byte 2 - Index + 2 15 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Byte 3 - Index + 3 23 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Bytes0 - 4 make a DWORD value in whole. We need to shift the bits &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' bits in each byte and sum them all together by multiplying by powers of 2 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' So the sub authority would be built by the following formula: &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' SUbAuthority = byte0*2^0 + Byte1*2^8 + byte2*2^16 + byte3*2^24 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' this be done using a simple short loop, initializing the power of two &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' variable ( p2 ) to 0 before the start an incrementing by 8 on each byte &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' and summing them all together. &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;p2 = 0 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;subtotal = 0 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for j = 1 to 4 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dblSubAuth = CDbl(ascb(midb(osid,i,1))) * (2^p2) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;subTotal = subTotal + dblSubAuth &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;p2 = p2 + 8 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i = i + 1 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;next &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt;' Convert the value to a string, add it to the SDDL Sid and continue &lt;/p&gt;
&lt;p&gt;' &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;strSDDL = strSDDL &amp;amp; &amp;quot;-&amp;quot; &amp;amp; cstr(subTotal) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;next &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;SDDL_SID = strSDDL &lt;/p&gt;
&lt;p&gt;end Function&lt;/p&gt;
&lt;p&gt;Function LocalAcctSID(strAcct)&lt;/p&gt;
&lt;p&gt;strComputer =&amp;quot;.&amp;quot;&lt;/p&gt;
&lt;p&gt;Set objWMIService = GetObject(&amp;quot;winmgmts:\\&amp;quot; &amp;amp; strComputer &amp;amp;&amp;quot;\root\cimv2&amp;quot;)&lt;/p&gt;
&lt;p&gt;Set colProfiles = objWMIService.ExecQuery(&amp;quot;Select * from Win32_UserProfile&amp;quot;)&lt;/p&gt;
&lt;p&gt;For Each objProfile in colProfiles&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Set objSID = objWMIService.Get(&amp;quot;Win32_SID.SID='&amp;quot; &amp;amp; objProfile.SID &amp;amp;&amp;quot;'&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;If UCase (strAcct) = UCase(objSID.AccountName) Then &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;strTargetAcctExist = &amp;quot;Yes&amp;quot; &lt;/p&gt;
&lt;p&gt;		If UCase(strTargetAcctDomain)= UCase(objSID.ReferencedDomainName) Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;		LocalAcctSID = objProfile.Sid&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;		Exit Function &lt;/p&gt;
&lt;p&gt;		End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;End If &lt;/p&gt;
&lt;p&gt;Next&lt;/p&gt;
&lt;p&gt;	If strTargetAcctExist &amp;lt;&amp;gt; &amp;quot;Yes&amp;quot; Then &lt;/p&gt;
&lt;p&gt;		WScript.Echo &amp;quot;Please check your target account! &amp;nbsp;Can not find &amp;quot; &amp;amp; UCase (strAcct) &amp;amp; _&lt;/p&gt;
&lt;p&gt;		 &amp;quot;'s profile on &amp;quot; &amp;amp; UCase (strTargetAcctDomain) &amp;amp; &amp;quot;.&amp;quot; &amp;amp; vbNewLine &amp;amp; _&lt;/p&gt;
&lt;p&gt;		 &amp;quot;If the account does exist, you need to log in as &amp;quot; &amp;amp; UCase (strAcct) &amp;amp; &amp;quot; on this computer first.&amp;quot;&lt;/p&gt;
&lt;p&gt;		WScript.Quit&lt;/p&gt;
&lt;p&gt;	End If &lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3325864" width="1" height="1"&gt;</description></item><item><title>re: Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3263450</link><pubDate>Mon, 13 Jul 2009 18:24:52 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3263450</guid><dc:creator>greener85</dc:creator><description>&lt;p&gt;Hey Shrimp's Stell,&lt;/p&gt;
&lt;p&gt;I have to be honest here with you, I have not really taken the time to learn anything at this point about Powershell scripting in general.&lt;/p&gt;
&lt;p&gt;However, I think your script is going to have a problem unless both the source and target accounts have logged onto the machine at least once. &amp;nbsp;Since you are calling the WMI Win32_UserAccount class.&lt;/p&gt;
&lt;p&gt;Rob Greene&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3263450" width="1" height="1"&gt;</description></item><item><title>re: Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3259667</link><pubDate>Mon, 29 Jun 2009 18:58:58 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3259667</guid><dc:creator>the shrimp's steel</dc:creator><description>&lt;p&gt;thank's a lot, i will try your script Rob, but if it's doesn't works with my park, this powerShell Scritp works ? (I just change in row 2 &amp;quot;Domain='Tralala'&amp;quot;&lt;/p&gt;
&lt;p&gt;[code]&lt;/p&gt;
&lt;p&gt;$original_user = get-wmiobject &amp;quot;Win32_UserAccount WHERE Name='user1' AND Domain='Tralala'&amp;quot;&lt;/p&gt;
&lt;p&gt;$new_user = get-wmiobject &amp;quot;Win32_UserAccount WHERE Name='user1' AND Domain='CONTOSO'&amp;quot;&lt;/p&gt;
&lt;p&gt;$profile = get-wmiobject &amp;quot;Win32_UserProfile WHERE SID='$($original_user.SID)'&amp;quot;&lt;/p&gt;
&lt;p&gt;$profile.ChangeOwner($new_user.SID, 0)&lt;/p&gt;
&lt;p&gt;[/code]&lt;/p&gt;
&lt;p&gt;And i have a another question for both script (vbs and PowerShell), when do I run the script ? when I'm the admin of the first domain (source) or the final domain (target), after created a user profil in the new domain ?&lt;/p&gt;
&lt;p&gt;by default, your script doesn't delete the source account I guess ?&lt;/p&gt;
&lt;p&gt;Rob, Do you marry me ?&lt;/p&gt;
&lt;p&gt;I have no further question.&lt;/p&gt;
&lt;p&gt;the shrimp's stell&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3259667" width="1" height="1"&gt;</description></item><item><title>re: Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3233777</link><pubDate>Fri, 01 May 2009 02:14:45 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3233777</guid><dc:creator>greener85</dc:creator><description>&lt;p&gt;Hey perennialmind,&lt;/p&gt;
&lt;p&gt;Thats great coding.&lt;/p&gt;
&lt;p&gt;I am sorry to hear that you had issues with the VBScript.&lt;/p&gt;
&lt;p&gt;Rob Greene&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3233777" width="1" height="1"&gt;</description></item><item><title>re: Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3233753</link><pubDate>Fri, 01 May 2009 00:42:13 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3233753</guid><dc:creator>perennialmind</dc:creator><description>&lt;p&gt;For what it's worth, I ran into some trouble with the VBScript replacement and ended up using the following PowerShell script instead. &amp;nbsp;As Rob Greene suggested, I pulled the SIDs from Win32_UserAccount. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;[code]&lt;/p&gt;
&lt;p&gt;$original_user = get-wmiobject -class &amp;quot;Win32_UserAccount&amp;quot; -namespace &amp;quot;root\cimv2&amp;quot; -filter &amp;quot;Name='user1' AND LocalAccount=True&amp;quot;&lt;/p&gt;
&lt;p&gt;$new_user = get-wmiobject -class &amp;quot;Win32_UserAccount&amp;quot; -namespace &amp;quot;root\cimv2&amp;quot; -filter &amp;quot;Name='user1' AND Domain='CONTOSO'&amp;quot;&lt;/p&gt;
&lt;p&gt;$profile = get-wmiobject -class &amp;quot;Win32_UserProfile&amp;quot; -namespace &amp;quot;root\cimv2&amp;quot; -filter &amp;quot;SID='$($original_user.SID)'&amp;quot;&lt;/p&gt;
&lt;p&gt;$profile.ChangeOwner($new_user.SID, [uint32]0)&lt;/p&gt;
&lt;p&gt;[/code]&lt;/p&gt;
&lt;p&gt;Which could be even shorter:&lt;/p&gt;
&lt;p&gt;[code]&lt;/p&gt;
&lt;p&gt;$original_user = get-wmiobject &amp;quot;Win32_UserAccount WHERE Name='user1' AND LocalAccount=True&amp;quot;&lt;/p&gt;
&lt;p&gt;$new_user = get-wmiobject &amp;quot;Win32_UserAccount WHERE Name='user1' AND Domain='CONTOSO'&amp;quot;&lt;/p&gt;
&lt;p&gt;$profile = get-wmiobject &amp;quot;Win32_UserProfile WHERE SID='$($original_user.SID)'&amp;quot;&lt;/p&gt;
&lt;p&gt;$profile.ChangeOwner($new_user.SID, 0)&lt;/p&gt;
&lt;p&gt;[/code]&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3233753" width="1" height="1"&gt;</description></item><item><title>re: Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3218089</link><pubDate>Wed, 25 Mar 2009 22:09:55 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3218089</guid><dc:creator>TechRon</dc:creator><description>&lt;p&gt;I know it has been a while, and this thread is likely dead - but I recently tested my current version of the script on a Windows 7 beta installation and after a couple of minor tweaks to the error checking bits, it now works with Windows 7 just fine. (Though I still haven't gone back to try to fit in the 'move back to a local account' option...)&lt;/p&gt;
&lt;p&gt;Oh,... and our mass migration of the Novell users went beautifully.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3218089" width="1" height="1"&gt;</description></item><item><title>Top AskDS Blog Posts</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3156578</link><pubDate>Thu, 20 Nov 2008 00:52:21 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3156578</guid><dc:creator>Ask the Directory Services Team</dc:creator><description>&lt;p&gt;We’ve been at this for over a year (since August 2007), with more than 100 posts (127 to be exact), so&lt;/p&gt;
&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3156578" width="1" height="1"&gt;</description></item><item><title>Das "Active Directory" Team online...</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3130801</link><pubDate>Wed, 01 Oct 2008 17:58:52 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3130801</guid><dc:creator>.: Michael Korp :.</dc:creator><description>&lt;p&gt;Auch das Active Directory Team betreibt ein Blog , dass ich interessant zu lesen finde. Gestolpert dar&amp;amp;#252;ber&lt;/p&gt;
&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3130801" width="1" height="1"&gt;</description></item><item><title>re: Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3127824</link><pubDate>Wed, 24 Sep 2008 19:59:47 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3127824</guid><dc:creator>greener85</dc:creator><description>&lt;p&gt;Hey Ron,&lt;/p&gt;
&lt;p&gt;So I took a look at you site listed above. &amp;nbsp;Top notch, I really like how you took the concept of the script and totally made it into something that you as well as other customers can use. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have to give you the extra kodos of adding all the documentation around how to use the script on the website. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for taking interest in our blogging efforts and giving back to the community with the additions to the script.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3127824" width="1" height="1"&gt;</description></item><item><title>re: Vista’s MoveUser.exe replacement</title><link>http://blogs.technet.com/b/askds/archive/2008/09/09/vista-s-moveuser-exe-replacement.aspx#3126089</link><pubDate>Fri, 19 Sep 2008 16:28:59 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3126089</guid><dc:creator>TechRon</dc:creator><description>&lt;p&gt;I might tackle this later... &amp;nbsp;I've been editing the script to make it closer to the old MoveUser.exe because we are going to begin a 'mass migration' next week, converting ~600 remaining users from Novell to AD. &amp;nbsp;I wanted my instructions for the team to be as close to identical for both XP and Vista as I could get them. &amp;nbsp;I've made so many changes now that simply posting a code-snip wouldn't work very well. &amp;nbsp;I'm telling our team to get the file from:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://tacklebox.cns.ohiou.edu/Moveuser/"&gt;http://tacklebox.cns.ohiou.edu/Moveuser/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you want to check out the changes in the file, let me know what you think... (and if you see any problems that I've missed.)&lt;/p&gt;
&lt;p&gt;Converting profiles back really isn't an issue right now - but in a University environment we get piles of requests that make all of us say &amp;quot;Why would they want to do that?&amp;quot; - But we aren't generally able to say 'no' unless it's trully imposible (and sometimes not even then...) So while I would like to have the 'ability' to move them back, I don't have the time to write and test that before we begin. And I doubt I'll have the need right away.&lt;/p&gt;
&lt;p&gt;So,... here we go........&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3126089" width="1" height="1"&gt;</description></item></channel></rss>