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

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

This does not work for some reason.  Any ideas would be extremely helpful, ty!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
In a CMD window, if set LOGONSERVER returns something like...

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

Open in new window

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

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
uncas1755Author Commented:
Thanks, that's what I had.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.