Storing PowerShell Script Variables In a Simple Text File
If you prefer not to change variables in your PowerShell script files, read on.
If you prefer to pass in fewer variables to your PowerShell script files, read on.
If you prefer to use a simple format for storing variables in a configuration file, read on.
Recently I made a batch of scripts for a customer request for Active Directory scripts to delegate via Cimitra. I didn't want the customer to have to make any changes to the scripts in order to match the Active Directory context required by the scripts. So I created a method so that all of the scripts can read variables from a common settings.cfg file. The trick, however, was to make it so that the person who edits the settings.cfg file doesn't have to know things such as XML or JSON file formatting rules.
The method I created uses a simple syntax of: VARIABLE_NAME=VALUE
So the only thing that ever needs to change is the "VALUE". For example:
SERVER_ADDRESS=192.168.1.2
If the server address changes to 192.168.13, the line would be changed to:
SERVER_ADDRESS=192.168.1.3
Rather than waxing on, I put a detailed Readme on GitHub and all of the scripts for you to get, and hack to your heart's content. The NewUser.ps1 script has the most verbose documentation.
Special thanks to Adam Bertram. Whenever I go Googling for answers to PowerShell Scripting, I seem to always stumble into Adam's work. For example, I learned how to "source" other PowerShell scripts from an article by Adam, which made the methods I used in the Active Directory scripts mentioned above, possible.
Script On!