Wednesday, June 24, 2009

Replacing folders on a network with psexec and xcopy

rem We can run a process remotely with psexec
rem
rem cmd /C allows us to run a process in a cmd window and it automatically terminates

for /l %a in (1,1,50) do psexec \\station-%a cmd /C "move c:\path\to\folder c:\path\to\backup"

rem Now lets replace that folder with a new one using xcopy
rem
rem We use our local copy of the folder c:\path\to\folder and copy it to each station
rem
rem /S /E /H /I switches for xcopy ensure that we get hidden files, sub directories, and empty directories. /I assumes that the destination is a folder.

for /l %a in (1,1,50) do start cmd /k "xcopy /S /E /H /I c:\path\to\folder \\station-%a\c$\path\to\folder"

No comments:

Post a Comment