• 0

batch to copy profiles


Question

I am currently replacing 30 systems at work, and each system had multiple users. So what I would like to do to their old systems is copy their profile consisting of ONLY My Docs, Favorites, and Desktop into another directory on the drive with their profilename as the directory.. for example, say I have the following users:

c:\documents and settings\Smith

c:\documents and settings\Jones

c:\documents and settings\Clark

I would like the batch file to traverse documents and settings to find the profile directories and copy them to:

c:\ProfileBackup\Smith\[favorites/mydocs/desktop]\

c:\ProfileBackup\Jones\[favorites/mydocs/desktop]\

c:\ProfileBackup\Clark\[favorites/mydocs/desktop]\

etc...

can this be done, and any clue how?

thanks!

Link to comment
https://www.neowin.net/forum/topic/514219-batch-to-copy-profiles/
Share on other sites

16 answers to this question

Recommended Posts

  • 0

I whipped this up in a few seconds but the drawback is that you have to make sure the user is logged in which you would like to copy the profile for and try this:

So if you're logged in as Mary, it will only copy Mary's profile. So if you have 4 profiles on a machine, you'll have to log in with each profile and run this script. Also, this is assuming you're using XP.

@ECHO OFF
MD C:\PROFILES
XCOPY "%USERPROFILE%\MY DOCUMENTS\*.*" "C:\PROFILES\%USERNAME%\My Documents\"
XCOPY "%USERPROFILE%\FAVORITES\*.*" C:\PROFILES\%USERNAME%\Favorites\
XCOPY "%USERPROFILE%\DESKTOP\*.*" C:\PROFILES\%USERNAME%\Desktop\
EXIT

  • 0

Well, the only thing I could find is if you create temporary variables for the users profiles:

So on the machine with 15 profiles you'd have to create 15 user variables and then expand the batch file accordingly. That's as knowledgeable I get with batch files.

Like this:

@ECHO OFF
SET USER1="USER NAME OF USER"
SET USER2="USER NAME OF USER 2"
SET USER3=
SET USER4=
MD C:\PROFILES

ECHO COPYING %USER1%'S PROFILE
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER1%\MY DOCUMENTS\*.*" "C:\PROFILES\%USER1%\My Documents\"
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER1%\FAVORITES\*.*" C:\PROFILES\%USER1%\Favorites\
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER1%\DESKTOP\*.*" C:\PROFILES\%USER1%\Desktop\

ECHO COPYING %USER2%'S PROFILE
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER2%\MY DOCUMENTS\*.*" "C:\PROFILES\%USER2%\My Documents\"
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER2%\FAVORITES\*.*" C:\PROFILES\%USER2%\Favorites\
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER2%\DESKTOP\*.*" C:\PROFILES\%USER2%\Desktop\

ECHO COPYING %USER3%'S PROFILE
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER3%\MY DOCUMENTS\*.*" "C:\PROFILES\%USER3%\My Documents\"
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER3%\FAVORITES\*.*" C:\PROFILES\%USER3%\Favorites\
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER3%\DESKTOP\*.*" C:\PROFILES\%USER3%\Desktop\

ECHO COPYING %USER4%'S PROFILE
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER4%\MY DOCUMENTS\*.*" "C:\PROFILES\%USER4%\My Documents\"
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER4%\FAVORITES\*.*" C:\PROFILES\%USER4%\Favorites\
XCOPY /Q "C:\DOCUMENTS AND SETTINGS\%USER4%\DESKTOP\*.*" C:\PROFILES\%USER4%\Desktop\
EXIT

  • 0

Here is another alternative way of doing what you wanted to do.

Try this VBS script it will copy what you want to the new folder.

Save As CopyUserFolders.vbs

Notes

Replace this strComputer = "." with strComputer = "SOME_COMPUTER_NAME" will in thoery

connect to a machine on the network. I can not test this part as I have no network.

strComputer = "."
On Error Resume Next 
 Dim F1, F2, colAccounts, objUser, StrUser
 Dim Act	 : Set Act = CreateObject("Wscript.Shell")
 Dim Fso	 : Set Fso = CreateObject("Scripting.FileSystemObject")
 Dim DocSet  : DocSet = Act.ExpandEnvironmentStrings("%SystemDrive%\Documents and Settings\")
 Dim DTop	: DTop = "\Desktop" 
 Dim Fav	 : Fav = "\Favorites"
 Dim MyDoc   : MyDoc = "\My Documents"
 Dim Profile : Profile = Act.ExpandEnvironmentStrings("%SystemDrive%\ProfileBackup\")
'/-> Create The folder If It Does Not Exists
  If Not Fso.FolderExists(Profile) Then Fso.CreateFolder(Profile) End If
  Set colAccounts = GetObject("WinNT://" & strComputer & "")
  colAccounts.Filter = Array("user")
'/-> Loop To Go Threw The User Accounts
   For Each objUser In colAccounts
   If Fso.FolderExists(DocSet & objUser.Name) Then 
   F1 = Profile & objUser.Name
'/-> Create The folder If It Does Not Exists
   If Not Fso.FolderExists(F1) Then Fso.CreateFolder(F1) End If 
   F2 = F2 & vbCrLf & objUser.Name 
'/-> Popup Messagebox 
   Act.Popup "Preparing To Copy this User : " & objUser.Name & vbCrLf &_
   "These Folder :" & DTop & ", " & Fav & ", " & MyDoc ,5,"Copy User Folders",4128
'/-> User Desktop
	StrUser = DocSet & objUser.Name & DTop
	Fso.CopyFolder(StrUser),(F1 & DTop)
'/-> User Favorite
	StrUser = DocSet & objUser.Name & Fav
	Fso.CopyFolder(StrUser),(F1 & Fav)
'/-> User My Documents
	StrUser = DocSet & objUser.Name & MyDoc
	Fso.CopyFolder(StrUser),(F1 & MyDoc)
	End If  
   Next
 Act.Popup "Completed Copying These Profiles" & vbCrLf & F2, 5, "Copy Users Folders", 4128
  • 0

Here is another alternative way of doing what you wanted to do.

Try this VBS script it will copy what you want to the new folder.

Save As CopyUserFolders.vbs

Notes

Replace this strComputer = "." with strComputer = "SOME_COMPUTER_NAME" will in thoery

connect to a machine on the network. I can not test this part as I have no network.

This is PERFECT! Thank you very much!

  • 0

Jake,

I just ran into a problem.. when I tried it on a windows2000 Laptop, it worked perfect. Now I'm at work and most of the systems are WinXP. What the script does now is copy the first one in the directory (Administrator) and then it doesn't move on to all the others.. any ideas?

Thanks again!

  • 0

Hi all,

You can write the batch version above a little bit shorter.

::--- snipp CopyProfile.bat

@echo off

:NextPlease

If [%1]==[] goto :eof

echo Copying %1's profile

For %%i in ("My Documents", Favorites, Desktop) do Echo Xcopy /q "C:\DOCUMENTS AND SETTINGS\%1\%%~i\*.*" "C:\profiles\%1\%%~i\"

shift & goto nextplease

::--- snapp CopyProfiles.bat

Demo [CMD-Prompt]:

> f:\Administrator\copyProfiles.bat userA MyUncle HisSister Another a b c d e f g h i j k l m

Copying userA's profile

Xcopy /q "C:\DOCUMENTS AND SETTINGS\userA\My Documents\*.*" "C:\profiles\userA\My Documents\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\userA\Favorites\*.*" "C:\profiles\userA\Favorites\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\userA\Desktop\*.*" "C:\profiles\userA\Desktop\"

Copying MyUncle's profile

Xcopy /q "C:\DOCUMENTS AND SETTINGS\MyUncle\My Documents\*.*" "C:\profiles\MyUncle\My Documents\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\MyUncle\Favorites\*.*" "C:\profiles\MyUncle\Favorites\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\MyUncle\Desktop\*.*" "C:\profiles\MyUncle\Desktop\"

Copying HisSister's profile

Xcopy /q "C:\DOCUMENTS AND SETTINGS\HisSister\My Documents\*.*" "C:\profiles\HisSister\My Documents\

"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\HisSister\Favorites\*.*" "C:\profiles\HisSister\Favorites\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\HisSister\Desktop\*.*" "C:\profiles\HisSister\Desktop\"

Copying Another's profile

Xcopy /q "C:\DOCUMENTS AND SETTINGS\Another\My Documents\*.*" "C:\profiles\Another\My Documents\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\Another\Favorites\*.*" "C:\profiles\Another\Favorites\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\Another\Desktop\*.*" "C:\profiles\Another\Desktop\"

Copying a's profile

Xcopy /q "C:\DOCUMENTS AND SETTINGS\a\My Documents\*.*" "C:\profiles\a\My Documents\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\a\Favorites\*.*" "C:\profiles\a\Favorites\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\a\Desktop\*.*" "C:\profiles\a\Desktop\"

Copying b's profile

Xcopy /q "C:\DOCUMENTS AND SETTINGS\b\My Documents\*.*" "C:\profiles\b\My Documents\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\b\Favorites\*.*" "C:\profiles\b\Favorites\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\b\Desktop\*.*" "C:\profiles\b\Desktop\"

Copying c's profile

.....

....

Copying m's profile

Xcopy /q "C:\DOCUMENTS AND SETTINGS\m\My Documents\*.*" "C:\profiles\m\My Documents\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\m\Favorites\*.*" "C:\profiles\m\Favorites\"

Xcopy /q "C:\DOCUMENTS AND SETTINGS\m\Desktop\*.*" "C:\profiles\m\Desktop\"

------------

P.S. The "echo" in front of the XCopy-command is only for demo. Just delete it to rumn the batch in your real envirinment.

@Threadowner:

You have to run this script with "the right rights". Run it with "runas" or "runasSpc" as Administrator.

Same problem occurs 2 posts later with the VBS-snippet.

HTH

Biber

Edited by Biber
  • 0

Jake,

I just ran into a problem.. when I tried it on a windows2000 Laptop, it worked perfect. Now I'm at work and most of the systems are WinXP. What the script does now is copy the first one in the directory (Administrator) and then it doesn't move on to all the others.. any ideas?

Thanks again!

I am not to sure why it is not working, it work fine on my XP machine.

The network stuff is not my best subject, perhaps someone who know more about networking may

be able to provide a reason as to why it not working correct.

Go to this link The Hey, Scripting Guy! Archive

See if they have anything there that may help you, then PM if you need any help with making the script.

  • 0

Biber,

Tried your script and didn't have any luck, it does nothing. Is there a mistake in there somewhere?

Jake,

How many accounts do you have on your PC? If it has multiple profiles, does it copy the needed folders from each profile?

  • 0

I have 4 user accounts on my computer and it copy each of there folders that are listed in the script.

Now this is on my local computer, I have only One computer so I can not test it on a network.

You can try this script I have made some changes in it.

Save As CopyUserFolder_V1.vbs

strComputer = "."
On Error Resume Next 
Dim F1, F2, colAccounts, ColItem, DocSet, Profile, StrUser
Dim Act	  : Set Act = CreateObject("Wscript.Shell")
Dim Fso	  : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim ObjWmi   : Set ObjWmi = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2") 
Dim Items	: Set Items = ObjWmi.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) 
Dim DTop	 : DTop = "\Desktop" 
Dim Fav	  : Fav = "\Favorites"
Dim MyDoc	: MyDoc = "\My Documents"
'/-> Sets The Path To The Folders Using Wmi Querry
  For Each ColItem in Items 
   DocSet = ColItem.SystemDrive & "\Documents and Settings\"
   Profile = ColItem.SystemDrive & "\ProfileBackup\"
  Next
'/-> Create The folder If It Does Not Exists
  If Not Fso.FolderExists(Profile) Then Fso.CreateFolder(Profile) End If
'/-> Loop To Go Threw The User Accounts
  Set Items = ObjWmi.ExecQuery("SELECT * FROM Win32_UserAccount",,48) 
   For Each ColItem in Items
   If Fso.FolderExists(DocSet & ColItem.Name) Then 
   F1 = Profile & ColItem.Name
'/-> Create The folder If It Does Not Exists
   If Not Fso.FolderExists(F1) Then Fso.CreateFolder(F1) End If 
   F2 = F2 & vbCrLf & ColItem.Name 
'/-> Popup Messagebox 
   Act.Popup "Preparing To Copy this User : " & ColItem.Name & vbCrLf &_
   "These Folder :" & DTop & ", " & Fav & ", " & MyDoc ,5,"Copy User Folders",4128
'/-> User Desktop
	StrUser = DocSet & ColItem.Name & DTop
	Fso.CopyFolder(StrUser),(F1 & DTop)
'/-> User Favorite
	StrUser = DocSet & ColItem.Name & Fav
	Fso.CopyFolder(StrUser),(F1 & Fav)
'/-> User My Documents
	StrUser = DocSet & ColItem.Name & MyDoc
	Fso.CopyFolder(StrUser),(F1 & MyDoc)
	End If  
   Next
Act.Popup "Completed Copying These Profiles" & vbCrLf & F2, 5, "Copy Users Folders", 4128
  • 0

@TheReasonUFailed

Biber,

Tried your script and didn't have any luck, it does nothing.

Is there a mistake in there somewhere?

No way. Impossible.

:no: ...okay... may be ...

I think, you forgot the parameters for usernames?

My scripts are running... even underwater... :whistle:

But, here I've just another (formatted) dirty oneliner which will

a) need no parameters

b) you CAN start without risk - the script will just display what it would do

:: -------------- snipp CopyProfiles.bat-------------
@For %%f in (Desktop Favorites "My Documents") do @(
for /f "delims=" %%i in ('dir /b /ad "%userprofile%\..\."') do @(
	  if exist "%userprofile%\..\%%i\%%~f" @(
		   xcopy /L /f /s /o /y /h /r "%userprofile%\..\%%i\%%~f\*.*" "c:\profiles\%%i\%%~f\"
)))
::--------------snapp CopyProfiles.bat-----------

Because of the XCOPY-parms "/L" and "/F" XCopy will display what it WILL copy without the /l parameter and with "/F" it will display the name of each source and target file.

Just try it out.

@excessdl

Really surem, both scripts are working. ;-)

Greetz from Bremen, Germany

Biber,

Mod of "Batch & Shell" on www.administrator.de

Edited by Biber
  • 0

Biber,

That's excellent -- thank you. Here is what I updated your code to, and it works perfectly:

md c:\%ComputerName%-ProfileBackup /y

@For %%f in (Desktop Favorites "My Documents") do @(
for /f "delims=" %%i in ('dir /b /ad "%userprofile%\..\."') do @(
	  if exist "%userprofile%\..\%%i\%%~f" @(
		   xcopy  /f /s /o /y /h /r "%userprofile%\..\%%i\%%~f\*.*" "c:\%ComputerName%-ProfileBackup\%%i\%%~f\"
)))

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • IT admins feel overwhelmingly "sick of" Microsoft and Windows 11 "garbage" apps, products by Sayan Sen From time to time, Microsoft brings changes to Windows 11, like improvements to its core features, such as the Start menu. One such change began rolling out recently with new policies, alongside a major bug fix that finally came after a year. However, not every change or "improvement" Microsoft makes may land. For example, earlier today, we wrote an article on the user reaction to an earlier design choice Microsoft made on Windows 10, when it was making an updated system specs page. You can read about the response, which was mostly negative, in our report here. Aside from general home users, professionals too, or at least some of them, are not very satisfied with Microsoft's overall policies and product functionalities. There are multiple instances of people ranting and complaining online, highlighting various issues they are facing or have faced recently when working with Microsoft products like Windows 11 or other Microsoft 365-based apps. For example, one such user, nostradamefrus, shared their experience on Reddit wherein they had to deal with an apparently buggy patch that broke authentication on Microsoft 365 apps when using RDS (Remote Desktop Services). The user wrote: "I'm so sick of Microsoft ... Their latest security patch broke probably our most important business app and uninstalling the patch breaks auth with 365 apps in RDS environments. So the options are either "you can't use the app" or "you can't use any Office 365 product" until they clean up their mess. But shoving Copilot into every facet of existence is what's really important, right? Someone break this company up already" On a separate thread, another Reddit user made a sarcastic post about the difficulties of working with Microsoft Graph PowerShell due to some of the command complexities. A commenter Trelfar chimed in, saying that much of it had to do with how it's inherently designed and alleged that it was done in that way by Microsoft to save time and budget. The words were certainly pretty harsh as they wrote: "The key to understanding why some of the commands are garbage is that every command is a wrapper that calls the native Graph API which requires JSON params, and many of them were procedurally implemented based on the underlying API so they could hit release ahead of the deprecation deadline for the modules it was replacing (like the AzureAD module). ... In short, it wasn't a design choice to make it work like this, it was a time/budget compromise to not put the effort in for some of the commands." Finally, a user Godzillian123, who is clearly very displeased about having to work daily with the management and deployment of Windows apps in their enterprise environment. The Redditor writes: "I wake up every day with but one lamenting thought in my head. That I will be having to deal with WindowsApps and appx style application at my organisation, for another day .... Sincerely whoever designed this. You are an idiot. .... you take the cake for biggest smart idiot award. I'm sure you think you are very clever, after all you architected a whole fresh new method of software deployment for your garbage Operating System that is still based on Windows NT. ..... Please reconsider your life choices and just throw this entire Microsoft store into the bin where it belongs, far away from enterprise machines where system admins live and don't have time to learn how your misguided application system design works." Interestingly, each and every one of these posts has been overwhelmingly upvoted by others in the sysadmin subreddit, indicating that these resonated with them. Of course, not everyone likely agrees, but they are probably in the minority. We also know Neowin is visited and read by many IT admins as well. Let us know in the comments below whether you feel the same way or whether you think they are simply overblown reactions from some frustrated, or perhaps overworked, employees. Source: Reddit (link1, link2, link3)
    • If you need Adobe Air, it's not dead actually. https://airsdk.harman.com/runtime  
    • WSCC - Windows System Control Center 10.0.4.0 by Razvan Serea Windows System Control Center is a free, portable program that allows you to install, update, execute and organize the utilities from various system utility suites. WSCC can install and update the supported utilities automatically. Alternatively, WSCC can use the http protocol to download and run the programs. WSCC is portable, installation is not required. Extract the content of the downloaded zip archive to any directory on your computer. Free for personal use. The setup packages and updates are downloaded directly from their author's website! This edition of WSCC supports the following utility suites: Windows Sysinternals Suite (including support for "Sysinternals Live" service) NirSoft Utilities Mitec and more... WSCC - Windows System Control Center 10.0.4.0 changelog: [CHANGED] installer now supports Windows on Arm [FIXED] large icons were not scaled correctly [FIXED] minor fixes Download: WSCC (64-bit) | 5.2 MB (Free for personal use) Download: WSCC (32-bit) | 6.2 MB View: WSCC Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Save 90% on a lifetime of AdGuard Family Plan (9 devices) by Steven Parker Today's highlighted Neowin Deal comes via our Apps + Software section, where you can get a lifetime subscription and save 90% on a lifetime AdGuard Family Plan. AdGuard is a unique program that has all the necessary features for what they claim to be "the best web experience." The software combines the an advanced ad blocker, a privacy protection module, and a parental control tool—all working in one app. This software deals with annoying ads, hides your data from a multitude of trackers, protects you from malware attacks, and even lets you restrict your kids from accessing inappropriate content. Install AdGuard and see the internet as it was supposed to be: clean and safe. Get rid of annoying banners, pop-ups & video ads once and for all Hide your data from the multitude of trackers & activity analyzers that swarm the web Avoid fraudulent and phishing website and malware attacks Protect your kids online by restricting them from accessing inappropriate & adult content Good to know Family Plan Length of access: lifetime This plan is only available to new users Redemption deadline: redeem your code within 30 days of purchase Max number of devices: 9 Access options: desktop & mobile Software version: AdGuard Family Updates included A lifetime subscription of AdGuard Family Plan normally costs $169.99, but this deal can be yours for just $15.97, that's a saving of $158.02. For full terms, specifications, and license info please click the link below. Get this AdGuard Family lifetime deal for just $15.97 (was $169.99) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. As an online publication, Neowin too relies on ads for operating costs and, if you use an ad blocker, we'd appreciate being whitelisted. In addition, we have an ad-free subscription for $28 a year, which is another way to show support! Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
  • Recent Achievements

    • Reacting Well
      Gideon Waxfarb earned a badge
      Reacting Well
    • First Post
      NovaEdgeX earned a badge
      First Post
    • One Month Later
      pahariyaseo earned a badge
      One Month Later
    • Week One Done
      pahariyaseo earned a badge
      Week One Done
    • Week One Done
      hadiaali45 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      419
    2. 2
      PsYcHoKiLLa
      142
    3. 3
      Nick H.
      90
    4. 4
      +Edouard
      80
    5. 5
      Steven P.
      77
  • Tell a friend

    Love Neowin? Tell a friend!