Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Read config file

Reply
 
Old 07-09-2008   #1 (permalink)
sylan


 
 

Read config file

I'm working on a script that will read in configuration information and
perform actions based on that.

Is there a "best practice" for doing this? Essentially, I'd like to read in
things like database name, input file locations, output file locations, etc.
Should I use INI, XML, something else?

My System SpecsSystem Spec
Old 07-09-2008   #2 (permalink)
RichS [MVP]


 
 

RE: Read config file

What is the configuration file for? is it an application you are writing.
Different applications have different config files so its difficult to
generalise. if you are writing the app I would suggest using XML
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"sylan" wrote:
Quote:

> I'm working on a script that will read in configuration information and
> perform actions based on that.
>
> Is there a "best practice" for doing this? Essentially, I'd like to read in
> things like database name, input file locations, output file locations, etc.
> Should I use INI, XML, something else?
My System SpecsSystem Spec
Old 07-09-2008   #3 (permalink)
Leo Tohill


 
 

RE: Read config file

The standard for .net applications is an xml file named after the exe, with a
..config suffix. For example, the config for hello.exe would be
hello.exe.config. The outer elements and some inner elements are
standardized, but the format can also be extended in a specified manner.
The System.Configuration.ConfigurationManager namespace of the framework
contains classes that support reading and writing such config files, and you
can of course call those methods from Powershell.

While you don't have an exe and thus won't get some of the automagic that
comes from the exe.config association, you could still follow that format and
use methods of the ConfigurationManager class to access a file with a name
like "myscript.ps1.config".

Even if you don't want to use the standard format for the content, I think
using xml and that .config naming convention would be a good idea.

- leo


"sylan" wrote:
Quote:

> I'm working on a script that will read in configuration information and
> perform actions based on that.
>
> Is there a "best practice" for doing this? Essentially, I'd like to read in
> things like database name, input file locations, output file locations, etc.
> Should I use INI, XML, something else?
My System SpecsSystem Spec
Old 07-10-2008   #4 (permalink)
sylan


 
 

RE: Read config file

That's what I needed. Thanks!

"Leo Tohill" wrote:
Quote:

> The standard for .net applications is an xml file named after the exe, with a
> .config suffix. For example, the config for hello.exe would be
> hello.exe.config. The outer elements and some inner elements are
> standardized, but the format can also be extended in a specified manner.
> The System.Configuration.ConfigurationManager namespace of the framework
> contains classes that support reading and writing such config files, and you
> can of course call those methods from Powershell.
>
> While you don't have an exe and thus won't get some of the automagic that
> comes from the exe.config association, you could still follow that format and
> use methods of the ConfigurationManager class to access a file with a name
> like "myscript.ps1.config".
>
> Even if you don't want to use the standard format for the content, I think
> using xml and that .config naming convention would be a good idea.
>
> - leo
>
>
> "sylan" wrote:
>
Quote:

> > I'm working on a script that will read in configuration information and
> > perform actions based on that.
> >
> > Is there a "best practice" for doing this? Essentially, I'd like to read in
> > things like database name, input file locations, output file locations, etc.
> > Should I use INI, XML, something else?
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
config file problems PowerShell
what is the web.config file? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46