[Powershell Tips] Convert String Data into a hash table (ConvertFrom-StringData)

In this post, I will demonstrate how can we save settings for a PowerShell script in a Text File to make it simple enough for people to edit the settings and not to mess around with the code in the script.

Let's say we want to use below settings in our script, we can save them in below format in a text file, for the ease of other users to edit related settings.


Note: We can name this text file with any extension "Smtp.Settings" or "Settings.dll" simple ".txt" Etc, Get-Content CMD will be able to fetch the data from it.

Next, if we get the content of this file in an array we have data in strings format.

So to convert this string data into a hash table, we can use the following command.


To convert the string data saved in the $Data array we can pipe that to this cmd.

$Data | ConvertFrom-StringData

Now we have all the data in a hash table in $data Array.
I hope you this post was informative please feel free to leave your feedback.
For more details on ConvertFrom-StringData please visit MSDN post here,