ConvertFrom-StringData

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

Syntax
      ConvertFrom-StringData [-StringData] string
            [CommonParameters]

Key
   -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. The comments are not included in the hash table.
CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.

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.

Example

Create a here string and convert to a hash table:

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

C:\PS> 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:

Select-String - Search through strings or files for patterns


© Copyright SS64.com 1999-2013
Some rights reserved