sentinel1705 Posted May 13, 2008 Share Posted May 13, 2008 (edited) I've been tasked to backup and migrate some 600+ user profiles and I'm 2/3 the way there. I've successfully scripted a recursive search that goes through all the user profile subfolders and renames their current profile from .ini to a .txt extension. Second, I've been able to push the new profile template from a single directory to all the userprofile\windows subdirectory.Now I need a script that will go through each user profile folder and copy three text strings from User#\windows\profile.txt and copy them over to the User#\windows\profile.ini. It should read something like this:Open file "D:\Profiles\User1\windows\profile.txt"Search------Setting1=Entry1------Setting2=Entry2------Setting3=Entry3Copy (to temp or clipboard)Close fileOpen File "D:\Profiles\User1\windows\profile.ini"Paste at end of file (there are some entries in the profile.ini already)------Setting1=Entry1------Setting2=Entry2------Setting3=Entry3Close fileRepeat for each profile under "D:\profiles\..\windows\I have a baseline script which could be way off course, but it can replace specific entries with specifc entries (already definied in the script) when targeting a specific file. Const ForReading = 1Const ForWriting = 2Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("D:\Profile\User1\windows\Profile.ini", ForReading)strText = objFile.ReadAllobjFile.ClosestrNewText = Replace(strText, "POSDELL", "TextEntry1")Set objFile = objFSO.OpenTextFile("D:\Profile\User1\windows\Profile.ini", ForWriting)objFile.WriteLine strNewTextobjFile.CloseSet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("D:\Profile\User1\windows\Profile.ini", ForReading)strText2 = objFile.ReadAllobjFile.ClosestrNewText2 = Replace(strText2, "CHGDELL", "TextEntry2")Set objFile = objFSO.OpenTextFile("D:\Profile\User1\windows\Profile.ini", ForWriting)objFile.WriteLine strNewText2objFile.CloseSet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("D:\Profile\User1\windows\Profile.ini", ForReading)strText3 = objFile.ReadAllobjFile.ClosestrNewText3 = Replace(strText3, "COSADELL", "TextEntry3")Set objFile = objFSO.OpenTextFile("D:\Profile\User1\windows\Profile.ini", ForWriting)objFile.WriteLine strNewText3objFile.Close"That is pretty much an edit I got from The Scripting Guy. To use that one, I made entries in the upgraded profile template for POSDELL, CHGDELL and COSADELL so that the search could target those standard entries and replace them with the entries from the profile.txt. Edited May 13, 2008 by sentinel1705 Link to comment Share on other sites More sharing options...
Smiley357 Posted May 14, 2008 Share Posted May 14, 2008 Im not eactly sure what you are looking for but here is a batch file that can find a string "setting#" and append it to the file.ini@echo offFOR /F "skip=2 tokens=*" %%i IN ('find /i "Setting1" D:\Profiles\User1\windows\profile.txt') DO echo %%i >> D:\Profiles\User1\windows\profile.iniFOR /F "skip=2 tokens=*" %%i IN ('find /i "Setting2" D:\Profiles\User1\windows\profile.txt') DO echo %%i >> D:\Profiles\User1\windows\profile.iniFOR /F "skip=2 tokens=*" %%i IN ('find /i "Setting3" D:\Profiles\User1\windows\profile.txt') DO echo %%i >> D:\Profiles\User1\windows\profile.ini Link to comment Share on other sites More sharing options...
sentinel1705 Posted May 14, 2008 Author Share Posted May 14, 2008 That might be close. I'll have to run it at work tomorr....later today. One thing though is the batch/script has to be recursive to search through all the subfolders for the .txt and .ini files (keeping them in pairs for each folder).I could do a script to make text entries of all the folder names and make it a filelist.txt of sorts, but I was looking to go a little neaterBasically some sort of batch/script that targets a parent folder called Profiles\ and will scan through each Profiles\User1\windows directory and compare profile.txt to profile.ini, copy 3 entries from profile.txt and append them to profile.ini, then do it again for Profiles\User2\Windows, Profiles\User3\Windows, Profiles\User4\Windows, Profiles\User5\Windows, etc. My user names are not as simple as 1, 2, 3, 4, but you get the idea. Link to comment Share on other sites More sharing options...
Yzöwl Posted May 14, 2008 Share Posted May 14, 2008 FOR /F "skip=2 tokens=*" %%i IN ('find /i "Setting1" D:\Profiles\User1\windows\profile.txt') DO echo %%i >> D:\Profiles\User1\windows\profile.iniI'm not sure that the for loop is needed>>D:\Profiles\User1\windows\profile.ini Find /i "data1=value1"<D:\Profiles\User1\windows\profile.txt Link to comment Share on other sites More sharing options...
sentinel1705 Posted May 14, 2008 Author Share Posted May 14, 2008 I'm not sure that the for loop is needed>>D:\Profiles\User1\windows\profile.ini Find /i "data1=value1"<D:\Profiles\User1\windows\profile.txtI ran that code as this@echo off>>"C:\Documents and Settings\Administrator\My Documents\GPUpgrade\Test\OFASNRAB1\windows\Profile.ini" Find /i "POSCURRENTWS=NRAB1" <"C:\Documents and Settings\Administrator\My Documents\GPUpgrade\Test\OFASNRAB1\windows\Profile.txt"pause And all I got was "press any key to continue" Link to comment Share on other sites More sharing options...
sentinel1705 Posted May 15, 2008 Author Share Posted May 15, 2008 Okay, I think I found one that works at eggheadcafeOption Explicit Dim oFSO, sFile1, sFile2, oFile1, oFile2, sText Set oFSO = CreateObject("Scripting.FileSystemObject") sFile1 = "C:\Test\User_057245\windows\profile.txt" sFile2 = "C:\Test\User_057245\windows\profile.ini" Set oFile1 = oFSO.OpenTextFile(sFile1, 1) Set oFile2 = oFSO.OpenTextFile(sFile2, 8) Do While Not oFile1.AtEndOfStream sText = Trim(ofile1.ReadLine) If InStr(sText, "CHGCurrentWS=") <> 0 Then oFile2.WriteLine sText End If If InStr(sText, "POSCurrentWS=") <> 0 Then oFile2.WriteLine sText End IfIf InStr(sText, "CHGPATH=") <> 0 Then oFile2.WriteLine sText End IfLoopThat code scanned profile.txt for sText and copied them over to Profile.ini. Now I need to know how to edit that code so that instead of targetting just one user folder, I target something like:C:\test\..\windows\profile.txt >> C:\test..\windows\profile.ini, so that it compares all the user profiles under C:\Test with the .txt and .ini sets in each windows subfolder.I generated a folderlist.ini and a folderlist.txt of all my profiles if that can be called somehow. Link to comment Share on other sites More sharing options...
Smiley357 Posted May 15, 2008 Share Posted May 15, 2008 This should work for you. Just change string1-3. I have tested this and it worked. So Yzowl code works. If it dont work for you check the file locations or the string your trying to look for. BTW you owe me a beer for the script. LOL @echo offdir C:\test\*.* /b -o:d | find /v "." > c:\dirs.txt for /f "tokens=*" %%a in (c:\dirs.txt) do call :search "%%a"del C:\dirs.txtgoto EOF:search>>"C:\Test\%~1\windows\profile.ini" Find /i "string1"<"C:\Test\%~1\windows\profile.txt">>"C:\Test\%~1\windows\profile.ini" Find /i "string2"<"C:\Test\%~1\windows\profile.txt">>"C:\Test\%~1\windows\profile.ini" Find /i "string3"<"C:\Test\%~1\windows\profile.txt" Link to comment Share on other sites More sharing options...
sentinel1705 Posted May 19, 2008 Author Share Posted May 19, 2008 (edited) This should work for you. Just change string1-3. I have tested this and it worked. So Yzowl code works. If it dont work for you check the file locations or the string your trying to look for. BTW you owe me a beer for the script. LOL @echo offdir C:\test\*.* /b -o:d | find /v "." > c:\dirs.txt for /f "tokens=*" %%a in (c:\dirs.txt) do call :search "%%a"del C:\dirs.txtgoto EOF:search>>"C:\Test\%~1\windows\profile.ini" Find /i "string1"<"C:\Test\%~1\windows\profile.txt">>"C:\Test\%~1\windows\profile.ini" Find /i "string2"<"C:\Test\%~1\windows\profile.txt">>"C:\Test\%~1\windows\profile.ini" Find /i "string3"<"C:\Test\%~1\windows\profile.txt"I tried that and even moved my test folder to the root drive so there wouldn't be any issues with folder names with spaces.Running this code@echo offpausedir C:\GPUpgrade\Test\*.* /b -o:d | find /v "." > c:\dirs.txt for /f "tokens=*" %%a in (c:\dirs.txt) do call :search "%%a"del C:\dirs.txtgoto EOFpause:search>>"C:\GPUpgrade\Test\%~1\windows\profile.txt" Find /i "CHGPATH="<"C:\GPUpgrade\Test\%~1\windows\profile.ini">>"C:\GPUpgrade\Test\%~1\windows\profile.txt" Find /i "CHGCurrentWS="<"C:\GPUpgrade\Test\%~1\windows\profile.ini">>"C:\GPUpgrade\Test\%~1\windows\profile.txt" Find /i "POSCurrentWS="<"C:\GPUpgrade\Test\%~1\windows\profile.ini"pauseProduced this image when run from the command prompt:Edit: Scratch that. It works, it just didn't give me any echo out so I never checked the actual files for comparison. When I did, there were about 50 entries of my search string in the other profile (because I kept running it over and over). One minor glitch though, is there any way to put a space/return line in there? When it copied over the first entry, it put it at the end of the preceeding entry - making them both on the same line.Edit x2. I just added a return character to the template and had it use that as the "spacer". Now it all works.This will be a real time saver. Thank you Edited May 19, 2008 by sentinel1705 Link to comment Share on other sites More sharing options...
sentinel1705 Posted May 19, 2008 Author Share Posted May 19, 2008 @ Smiley357, I have close to 200 profiles to target this at, how do I know when it is done? Link to comment Share on other sites More sharing options...
Smiley357 Posted May 20, 2008 Share Posted May 20, 2008 You can put an echo at the end of the scrip to let you know it’s finished. I’m guessing you don’t want a pause after every profile so you will need to remove the pause from the function. @echo offdir C:\test\*.* /b -o:d | find /v "." > c:\dirs.txt for /f "tokens=*" %%a in (c:\dirs.txt) do call :search "%%a"del C:\dirs.txtEcho script has finishedpausegoto EOF:search>>"C:\Test\%~1\windows\profile.ini" Find /i "string1"<"C:\Test\%~1\windows\profile.txt">>"C:\Test\%~1\windows\profile.ini" Find /i "string2"<"C:\Test\%~1\windows\profile.txt">>"C:\Test\%~1\windows\profile.ini" Find /i "string3"<"C:\Test\%~1\windows\profile.txt"Another option is to have it echo "script has finished" and wait x amout of time and then finish. All you have to do is replace the pause with this:Echo script has finishedping 127.0.0.0 -n 10 >nul This will wait for 10 seconds before it continues and in this case end. Link to comment Share on other sites More sharing options...
sentinel1705 Posted May 20, 2008 Author Share Posted May 20, 2008 I dumped all the profiles to my thumbdrive for testing and edited the paths accordingly, now I am getting the error message "The system cannot find the path specified."@echo offdir E:\Notes\GPUpgrade\TSProfiles*.* /b -o:d | find /v "." > E:\dirs.txt for /f "tokens=*" %%a in (E:\dirs.txt) do call :search "%%a"del E:\dirs.txtEcho The script has finishedping 127.0.0.0 -n 10 >nulgoto EOF:search>>"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.ini" Find /i "CHGPATH="<"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.txt">>"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.ini" Find /i "CHGCurrentWS="<"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.txt">>"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.ini" Find /i "POSCurrentWS="<"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.txt" Link to comment Share on other sites More sharing options...
sentinel1705 Posted May 20, 2008 Author Share Posted May 20, 2008 I dumped all the profiles to my thumbdrive for testing and edited the paths accordingly, now I am getting the error message "The system cannot find the path specified."@echo offdir E:\Notes\GPUpgrade\TSProfiles*.* /b -o:d | find /v "." > E:\dirs.txt for /f "tokens=*" %%a in (E:\dirs.txt) do call :search "%%a"del E:\dirs.txtEcho The script has finishedping 127.0.0.0 -n 10 >nulgoto EOF:search>>"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.ini" Find /i "CHGPATH="<"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.txt">>"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.ini" Find /i "CHGCurrentWS="<"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.txt">>"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.ini" Find /i "POSCurrentWS="<"E:\Notes\GPUpgrade\TSProfiles\%~1\windows\Profile.txt"Nevermind.... "dir E:\Notes\GPUpgrade\TSProfiles*.* " is not equal to "dir E:\Notes\GPUpgrade\TSProfiles\*.* Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now