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. 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.
The escape sequence \n can be used to create new lines within a block of text
Standard Aliases for ConvertFrom-StringData: none, but if you want to add a short alias like cfsd, set it with set-alias
This cmdlet was introduced in Windows PowerShell 3.0.
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
Convert a single-quoted here-string that contains multiple key/value pairs into a hash table. In this command, the value of the StringData parameter is a here-string, instead of a variable that contains a here-string. Either format is valid. The here-string includes a comment about one of the strings. Comments are valid in strings, provided that the comment is on a different line than a key/value pair:
convertfrom-stringdata -stringdata @'
Name = Disks.ps1
# Category is optional.
Category = Storage
Cost = Free '@Name Value
---- -----
Cost Free
Category Storage
Name Disks.ps1
“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
Select-String - Search through strings or files for patterns.
ConvertFrom-String - Extract and parse structured properties from a string.
ConvertFrom-SecureString - Convert a secure string into an encrypted standard string.