ConvertFrom-String

ConvertFrom-String has two different styles of operation. The first behaves much as ConvertFrom-Csv except that it does not discard characters that make up the CSV format. In the following example, the quote characters surrounding the first name are preserved:

PS> '"bob",tim,geoff' | ConvertFrom-String -Delimiter ',' -PropertyNames name1, name2, name3

name1 name2 name3
----- ----- -----
"bob" tim geoff

The default Delimiter (if the parameter is not supplied) is a space. The second operating mode of ConvertFrom-String is far more complex. A template must be defined for each element of data that is to be pushed into a property.

The following example uses ConvertFrom-String to convert the output from the tasklist command to an object:

$template = '{Task*:{ImageName:System Idle Process} {[Int]PID:0} {SessionName:Services} {Session:0} {Memory:24 K}}' 
tasklist |  
    Select-Object -Skip 3 | 
    ConvertFrom-String -TemplateContent $template | 
    Select-Object -ExpandProperty Task 

The Task* element denotes the start of a data record. It allows each of the remaining fields to be grouped together under a single object.

The ConvertFrom-String command is good at dealing with well formatted data that is already divided correctly. In the case of the tasklist command, the end of a single task (or data record) is denoted by a line break.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.151.220