Script/Tool to modify config files

Posted on 2011-10-21
Last Modified: 2012-05-12
Hi All

the scenarios is we have 100+ Servers.
I am looking for a script/Tool that would help me in updating config files, like maching.config or web.config or any other config file on the servers.

At times we need to modify a tag in machine.config. So this tool should ask for Search/Replace kind of thing where I will provide with multiple current tags in machine.config and will also provide new tags that I want to be replaced by the old one.

Also, it should provide with option to add new tag under some parent tag. Ie I will mention that I need to add new tag and then provide the name of parent tag under which I want the new tag to be added.

So, two things as of now

1) Ability to update existing tag
2) Ability to add new tag under some parent tag

Please let me know if you need any further clarification.

Thanks in advance
Question by:ghelaniabhishek
    LVL 51

    Expert Comment

    by:Bill Prew
    Are the config files all in the same format?  And can you post a sample of what that format is?


    Author Comment

    lets consider the file to be machine.config
    LVL 43

    Expert Comment

    by:Steve Knight
    Can you supply the informsation that Bill asked for so we can look?
    LVL 51

    Expert Comment

    by:Bill Prew
    I'm a bit leery to propose a generic updater for these files.  I believe they are basically well formed XML files, and as such a pure text search and replace approach could lead to errors in the xml structure in the file.  

    A proper approach likely needs to work with the file as a true xml document.  One approach to this is via PowerShell as in:

    But I'm not really a PowerShell expert, so things like the prompting and such you want would be better handled by someone else.

    You might also look at the tool based technique in this artical for additional thought:


    Author Comment

    Thanks for the reply bill.
    Yes, these are all XML based config file.  A simple search and replace tool would also work for me if you have anything available.

    two things the tool needs to do is

    1) Add new tag
    2) replace existing tag

    while adding new tag, you need to ask for the parent tag, ie the new tag should be added within which tag

    and while replacing existing tag, you can simply provide a search and replace kind of thing where we provide the entire code, you search for it and replace with the new one
    LVL 43

    Accepted Solution

    Agreed with you here Bill.  Powershell not got enough attention here yet for me either and updating in batch while possible is tricky with all those < > and the like in there.  VBScript easier but feels like pre-inventing the wheel.

    Is Powershell an option here, will suggest it gets added as a zone for you.

    Meanwhile this sounded like it might be useful though having looked more it is out of date and not suitable:

    I haven't tried it yet but JExamXML sounds promising here:

    So end of the line for anything I can do easily on this one, will see if Powershell people have a two liner for you!

    LVL 12

    Assisted Solution

    I believe Chef does it all - see Open source; highly configurable and customizable.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article will show, step by step, how to integrate R code into a R Sweave document
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now