How to use the ConvertFrom-StringData command in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

The ConvertFrom-String command converts the String to the Hashtable format as shown below.


PS C:\> "This is string" | ConvertFrom-String


P1 P2 P3
-- -- --
This is string

In the above example, We haven’t specified any header so that the output is separated the delimiter by space P1, P2 and continuous. By default, this command separates the string with a ‘=’ delimiter as shown below.


$stringhash = @"
   Name = Spooler
   Starttype = Manual
   Status = Stopped
$stringhash | ConvertFrom-StringData


Name      Value
----      -----
Status    Stopped
Starttype Manual
Name      Spooler

Another method we can use is by separating string Keys and values with a delimiter parameter. This parameter is only available in the PowerShell core 7.1 version.


$stringhash = @"
   Name | Spooler
   Starttype | Manual
   Status | Stopped
ConvertFrom-StringData -StringData $stringhash -Delimiter '|'

We can also use the below method.

PS C:\> $stringhash = "Name = Spooler `n StartType = Manual `n Status = Stopped"
PS C:\> ConvertFrom-StringData -StringData $stringhash
Name Value
---- -----
Status Stopped
Name Spooler
StartType Manual
Updated on 30-Mar-2021 14:01:32