PowerShell Logo Small

ConvertFrom-String



This is the built-in help made by Microsoft for the command 'ConvertFrom-String', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Extracts and parses structured objects from string content.

SYNTAX


ConvertFrom-String [-Delimiter [<String>]] [-PropertyNames [<String[]>]] -InputObject <String> [<CommonParameters>]
ConvertFrom-String [-IncludeExtent] [-TemplateContent [<String>]] [-TemplateFile [<String>]] [-UpdateTemplate [<String>]] -InputObject <String> [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


You can run the ConvertFrom-String cmdlet to add structure to unstructured string content. ConvertFrom-String generates an object by parsing text from a traditional text
stream. For each string in the pipeline, the cmdlet splits the input by either a delimiter or a parse expression, and then assigns property names to each of the resulting
split elements. You can provide these property names; if you do not, they are automatically generated for you.


The cmdlet’s default parameter set, ByDelimiter, splits exactly on the regular expression delimiter. It does not perform quote matching or delimiter escaping as the
Import-Csv cmdlet does.


The cmdlet’s alternate parameter set, TemplateParsing, generates elements from the groups that are captured by a regular expression.


This cmdlet supports two modes: basic delimited parsing, and automatically-generated, example-driven parsing.


Delimited parsing, by default, splits the input at white space, and assigns property names to the resulting groups. You can customize the delimiter by piping the
ConvertFrom-String results into one of the Format-* cmdlets, or by adding the Delimiter parameter.


The cmdlet also supports automatically-generated, example-driven parsing based on the FlashExtract research work by Microsoft Research.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/?LinkID=507579
ConvertFrom-String:
Example-based text parsing
ConvertFrom-StringData
ConvertFrom-Csv
ConvertTo-Xml

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>"Hello World" | ConvertFrom-String



The following example generates an object with default property names, P1 and P2. The results are "P1=Hello" and "P2=World".






-------------------------- EXAMPLE 2 --------------------------

PS C:\>"Hello World" | ConvertFrom-String -Delimiter "ll"



The following example generates an object with "P1=He" and "P2=o World", by specifying the "ll" in "Hello " as the delimiter.






-------------------------- EXAMPLE 3 --------------------------

PS C:\>"Phoebe Cat" | ConvertFrom-String -TemplateContent {PersonInfo*:{Name:Phoebe Cat}}PS C:\>$template = {PersonInfo*:{Name:Phoebe Cat}}
"Phoebe Cat" | ConvertFrom-String -TemplateContent $template



The following example uses an expression as the value of the TemplateContent parameter to instruct Windows PowerShell that the string you’re piping to ConvertFrom-String has
a property of Name.

You can also save the expression in a variable, then use the variable as the value of the TemplateContent parameter, as shown here.






-------------------------- EXAMPLE 4 --------------------------

PS C:\>"Hello World" | ConvertFrom-String -PropertyNames FirstWord,SecondWord



The following example generates an object that contains two properties, FirstWord and SecondWord. The results are "FirstWord=Hello" and "SecondWord=World.






-------------------------- EXAMPLE 5 --------------------------

PS C:\>"123 456" | ConvertFrom-String -PropertyNames String,Int



The following example generates an object with default property names P1 and P2, but property types String and Int (for Integer) are identified. The results are "P1=123" and
"P2=456". The second property is an integer, not a string.