Application Security

 

When developing scripts (and almost anything else) I prefer to hard-code any settings thay may need to be changed later.  One method that I employ while writing PowerShell scripts is the use of a settings.ini file.  In this file I can place any configuration information and when I need to change a setting or run the script against another environment I only need to modify a single file.

Within the file I can group thing logically and assign simple values that can be used within the scripts.  When the PowerShell script runs, it will read the contents of the settings.ini file into a hashtable for easy retreival.  A hastable is good becase it provides a simple key/value pair that makes getting the values easy.

This PowerShell snippet will read the contents of an .ini style settings file into a HashTable.

Example Setting.ini

PowerShell Command

*The above statement may be broken into multiple lines for web display only.

After executing the code snippet, a variable ($h) will contain the values in a HashTable.

Key Value
MySetting1 value
VerboseLogging True
WaitForTime 20
OutputFile “C:output.log”
InputFile “C:Users.txt”

To get an item from the table use the command