We help IT Professionals succeed at work.

Copy a file/folder from a local DC instead of a specific location

I need to copy a folder with image files from a local DC that users are logging into.

Currently I have it mapped to ONE particular DC in our domain and use a GPO to run this bat file for all workstations. As you can see from the snippet of Batch command below, I use pushd to map to the directory that houses the folder I want to copy directly so that I can then just copy folder1 to a local workstations public pictures folder on Win7x32 systems after a domain login by the user.

see here for the current way I copy the folder:  
      pushd \\dc4\NETLOGON\
          XCOPY folder1  C:\Users\Public\Pictures\folder1  /S /I
      popd


I am trying to use %logonserver% instead of the specific DC to copy the folder so that it will copy the folder from whatever local DC the user has logged into...

see here my attempt to do this:

      pushd \\%logonserver%\NETLOGON\
          XCOPY folder1  C:\Users\Public\Pictures\folder1  /S /I
      popd


This does not work for some reason.  Any ideas would be extremely helpful, ty!
Comment
Watch Question

End-user support
Commented:
In a CMD window, if set LOGONSERVER returns something like...
LOGONSERVER=\\servername

...then you can do this:

for /f "delims=\ tokens=2*" %%a in ('set logonserver') do (set LS=%%a)
pushd \\%LS%\NETLOGON\
XCOPY folder1  C:\Users\Public\Pictures\folder1  /S /I
popd

Open in new window


Or, much simpler, just get rid of the \\ prefix...
pushd %LOGONSERVER%\NETLOGON\
XCOPY folder1  C:\Users\Public\Pictures\folder1  /S /I

Open in new window

Author

Commented:
Thanks, that's what I had.