Convert a string containing one or more key/value pairs to a hash table.

      ConvertFrom-StringData [-StringData] string

   -StringData string
      The string to be converted. Accepts piped data (string)

      The value of this parameter must be a string enclosed in single or double
      quotes or a here-string containing one or more key/value pairs.
      Each key/value pair must be on a separate line, or
      each pair must be separated by newline characters (`n).
      You can include comments in the string, but the #comments cannot be on
      the same line as a key/value pair. Comments are not included in the hash table.

ConvertFrom-StringData converts a string that contains one or more key/value pairs into a hash table. Because each key/value pair must be on a separate line, here-strings are often used as the input format.

ConvertFrom-StringData is considered to be a safe cmdlet that can be used in the DATA section of a script or function. For more information, see help about_Data_Sections.


Create a here string and convert to a hash table:

PS C:\>$my_here_string = @'
ss64 = The first line of data.
# This is a comment
ss65 = Another line of data.
ss66 = The last line of data.

PS C:\> convertfrom-stringdata -stringdata $my_here_string

“A few can touch the magic string, and noisy fame is proud to win them: Alas for those that never sing, but die with all their music in them!” - Oliver Wendell Holmes

Related PowerShell Cmdlets

Select-String - Search through strings or files for patterns

Copyright © 1999-2024
Some rights reserved