Easy Parsing of Setting Files (Part 1)

by Jul 26, 2017

Let’s assume you want to save settings to a file in the most simplest form. Your settings may look like this:

$settings = '
Name=Weltner
FirstName=Tobias
ID=12
Country=Germany
Conf=psconf.eu
'

You could save these settings to file using Set-Content, and read them back using Get-Content.

Yet how would you parse the information so that you can access individual items? There is a cmdlet called ConvertFrom-StringData that turns your key-value pairs into a hash table:

$settings = @'
Name=Weltner
FirstName=Tobias
ID=12
Country=Germany
Conf=psconf.eu
'@

$hash = $settings | ConvertFrom-StringData

$hash.Name
$hash.Country

Twitter This Tip! ReTweet this Tip!