I want to generate a batch file that will copy all *.doc and *.xls file types from a user's profile. I will then set the batch file to run automatically via Scheduled Tasks after-hours when all users are logged out. Here is what I have:
for %%x in (doc xls) do xcopy c:\Users\user1\*.%%x "\\server\i$\User Backups\user1\%computername%\" /c /i /y /s /d
This works fine, however, I need to generate a line item in the batch file for each and every user in our organization (user1, user2, etc.) so that I hit all profiles. When new users are hired, the file needs to be updated with their profile info. Ideally, I'd like something a bit more automated that is similar to this:
for %%x in (doc xls) do xcopy %userprofile%\*.%%x "\\server\i$\User Backups\%username%\%computername%" /c /i /y /s /d
The downfall is that by using %userprofile% in place of the 'user1' input, it only runs against the currently logged in user. Is there another option I could incorporate that wouldn't care about the currently logged in user, and instead just run against all user profiles on a machine?
You could use reg query to get the list of user profiles from the registry, but you only care about users who have a folder under C:\Users, so just loop over those:
for /d %%u in (C:\Users\*) do for %%x in (doc xls) do xcopy C:\Users\%%~nu\*.%%x "\\server\i$\User Backups\%%~nu\%computername%\" /c /i /y /s /d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With