Jump to content

Recommended Posts

Posted

Hello All,

 

I have a batch file I am developing that will create a directory and copy some files to it.

mkdir \\SERVER\username$\directoryName
copy \\SERVER\directoryName\a.file \\SERVER\username$\directoryName

My current version uses a specific username but I want to be able to run this batch for all teaching staff. Is there something I can replace the username$ in the mkdir command with something that will capture all (the teaching staff all belong to a "Teaching Staff" group)? I've had a search of the web but don't really know what search terms to use :confused:

 

Many thanks, TomHD

Guest obsidianpillar
Posted

If your trying to pick up the names from AD and then pre-create the folders, I'm not sure of the best way to do this. However, if your trying to create the folders at logon I'd just scrap the Batch Script and use Group Policy Files with Item Level Targeting, use the path as "\\SERVER\Share\%USERNAME%" as the path and then uncheck "archive". Then click Common, Check "Item-Level Targeting", Click "Targeting...", New Item, Security Group, click on the "..." option and add in the "Teaching Staff" Group. This will create a folder with the Teacher's Username in when the user logs in.

 

Hope this helps.

 

Best,

Tom

Posted
I did this a while ago, but struggling to remember. Try %USERPROFILE% variable and apply that logon script to the teaching staff group in GP?
Posted (edited)

I don't know if it's suitable for what you want but, if you put all the teacher's usernames into a text file (called file.txt in this example), by exporting from AD, then you could use something like this, which will run the robocopy command (providing your original "directroyname" and the target "directoryname" are the same then it should do what you want) for every name in the list. If the robocopy command doesn't work right then your mkdir/copy script could be put in using %var% for the username variable.

 

FOR /F %%A IN (file.txt) DO IF "%%A" NEQ "" SET VAR=%%A&call :process:process
robocopy \\SERVER\directoryName\ \\SERVER\%Var%$\directoryName /mir

 

It's also worth noting that, in windows, %username% in a command/batch file will return the currently logged on user.

 

Hope this is of some help.

Edited by Rob_D

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...