I've really taken a liking recently to using XML files for storing configuration values for my PowerShell scripts. Most times, I do it to make it a "one-stop shop" for updating config values.
I create a lot of scripts for people who may not have the most experience when it comes to reading code. It's definitely easier to say, "Update config.xml and don't worry about changing anything in the PowerShell script." Most people will look at a PowerShell script and go cross-eyed... this prevents that.
I decided since I like it so much, I'm going to show you how it's done. It's a lot easier than I was expecting it to be... check this out:
Create a new XML file called
config.xml and add the following information to it:
Next, create a new PowerShell script in the same directory called
XMLConfig.ps1 and add the following information to it:
In the above script, we're importing
config.xml into the variable
$ConfigFile. Afterwards, we're sending the values of the
Website sections of the XML file to the PowerShell Console host.
In just 4 easy steps, you've created your own XML Configuration file to use along side your favorite PowerShell scripts going forward!