Jump to content

Script to copy a file or folder to multiple users Documents folder.


Recommended Posts

Posted (edited)

Hi,

 

I am just trying to teach my self some basic scripts, am totally new to coding. What i am looking to do is to comprise a script to copy files or folder from one location to all users "my documents" folder.

 

currently this is on windows 2008 r2 platform.

 

the files needed to be copied would be on a server eg \\fileserver\Filefolder

the folders needing the files are laid out like this \\fileserver\redirected$\Pupils\2013start\JBloggs13\My Documents

\\fileserver\redirected$\Pupils\2013start\TBloggs13\My Documents

 

so my problem is how do i get the script to copy to all the usernames "my documents folder" without manually specifying the unc path of all of them. Also does the fact there is a space in my documents affect the layout of the script.

 

the users dont have a home path specified in AD, they are redirected through Group Policy.

Edited by Menov321
Posted
might be easier to use gpp and tell it to copy file from a to my documents for the group 2013 or just use a logon script copy "\\server\share\source.txt" "%homedrive%\my documents\source.txt"
Posted

I had to do this recently. Here's (roughly) what I did:

 

Open CMD prompt

Type dir >names.txt to get a list of all the students' folders

Open the text file in Excel

Use "Concatenate" command to create a load of commands which read something like

copy C:\Folders\Files\*.* D:\Users\Students\%Names%\

Copy and paste the Excel data into Notebook

Save as .bat

Run it

  • Thanks 2
Posted

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(homedirectory=*server1*))" -limit 500 | dsget user -hmdir -samid -c > out.txt

for /f "skip=1 tokens=1,2" %%a in (out.txt) do copy \\server\share\file %%a\folder\file

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...