Replace File under each user profile in TS environment

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jbertone9
Posts: 2
Joined: 19 Aug 2012 09:58

Replace File under each user profile in TS environment

#1 Post by jbertone9 » 19 Aug 2012 10:12

Can someone offer some guidance on this one:

On Windows 2008 Terminal Server:

xxx - Couple Hundred User Profiles

For each user profile that has a ".Synoptix" sub folder

C:\Users\xxx\.Synoptix

replace the defaults.xml within ".Synoptix" with an updated one.


Our in house TS administrator is out on vacation, and I am fumbling through fixing this issue.
I have direct access to the server as an administrator, so I could step through each folder and replace the file one by one... but there must be an easier way.
Thanks

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Replace File under each user profile in TS environment

#2 Post by abc0502 » 19 Aug 2012 10:31

Test this before you use it

Code: Select all

@Echo off

set "xml=C:\defaults.xml"
set "users=C:\Users"

:: %%z will be assigned to the user's profile names
For /F "tokens=*" %%z in ('Dir /B /A:D "%users%"') Do (
   IF Exist "%users%\%%z\.Synoptix" Copy /y "%xml%" "%users%\%%z\.Synoptix"
)
pause

jbertone9
Posts: 2
Joined: 19 Aug 2012 09:58

Re: Replace File under each user profile in TS environment

#3 Post by jbertone9 » 19 Aug 2012 11:47

Thank you so much.
In my eariler testing and trial i was missing the"token" part- thanks for the tip i will test the code later tonight.

I greatly appreciate your quick response.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Replace File under each user profile in TS environment

#4 Post by Squashman » 19 Aug 2012 12:32

jbertone9 wrote:Thank you so much.
In my eariler testing and trial i was missing the"token" part- thanks for the tip i will test the code later tonight.

I greatly appreciate your quick response.

You must have missed reading this when you read the help file for the for command.

Code: Select all

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]

    file-set is one or more file names.  Each file is opened, read
    and processed before going on to the next file in file-set.
    Processing consists of reading in the file, breaking it up into
    individual lines of text and then parsing each line into zero or
    more tokens.  The body of the for loop is then called with the
    variable value(s) set to the found token string(s).  By default, /F
    passes the first blank separated token from each line of each file.
    Blank lines are skipped.  You can override the default parsing
    behavior by specifying the optional "options" parameter.  This
    is a quoted string which contains one or more keywords to specify
    different parsing options.  The keywords are:

        eol=c           - specifies an end of line comment character
                          (just one)
        skip=n          - specifies the number of lines to skip at the
                          beginning of the file.
        delims=xxx      - specifies a delimiter set.  This replaces the
                          default delimiter set of space and tab.
        tokens=x,y,m-n  - specifies which tokens from each line are to
                          be passed to the for body for each iteration.
                          This will cause additional variable names to
                          be allocated.  The m-n form is a range,
                          specifying the mth through the nth tokens.  If
                          the last character in the tokens= string is an
                          asterisk, then an additional variable is
                          allocated and receives the remaining text on
                          the line after the last token parsed.
        usebackq        - specifies that the new semantics are in force,
                          where a back quoted string is executed as a
                          command and a single quoted string is a
                          literal string command and allows the use of
                          double quotes to quote file names in
                          file-set.

Post Reply