ConvertFrom-String (TemplateContent)

Welcome Forums General PowerShell Q&A ConvertFrom-String (TemplateContent)

This topic contains 3 replies, has 4 voices, and was last updated by

3 months ago.

  • Author
  • #110851

    Points: 0
    Rank: Member


    I would like to extract the following data:

    • UserStateRunning IE:ProtectedMode
    • Doc:ProtectedMode
    • vSentry:Enabled
    • stage1: Stage1Image0001
    • stage2: Stage2Image0001
    • locationPath: C:\ProgramData\Bromium\vSentry\\Stage2\Stage2Image0001
    • systemMemory: 896MB
    • cpuCount: 2
    • touchEnabled: 1
    • generationCount: 1
    • creationTime: 2018-08-23T16:23:39.0000

    From the following string:

    UserStateRunning IE:ProtectedMode Doc:ProtectedMode vSentry:Enabled
    Running Since[2018-08-27T07:57:59.0000]
    Currently Running Template:
     stage1: Stage1Image0001
     stage2: Stage2Image0001
     locationPath: C:\ProgramData\Bromium\vSentry\\Stage2\Stage2Image0001
     systemMemory: 896MB
     cpuCount: 2
     touchEnabled: 1
     generationCount: 1
     creationTime: 2018-08-23T16:23:39.0000

    I would like the text before the column to be the header and the text after the column to be the data.

    I've tried numerous of different ways in my TemplateContent, but with no success.

    Thanks in advance!

  • #111316

    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    It would probably be helpful for people to see what you've tried. Everyone's happy to try and help, but asking for a from-scratch solution is often more time-heavy than folks are able to accommodate :).

  • #111425

    Points: 31
    Rank: Member

    This is a link to another post about Convert-FromString.   It is a worthwhile command to learn and understand.   I use it all the time to parse semi-structured text files.

  • #111454

    Points: 289
    Helping Hand
    Rank: Contributor

    If you can get it to break everything down into a series of lines (one item per line) then you can use ConvertFrom-StringData.

    $InputData -replace '$(?< =[\w ]+):','=' | ConvertFrom-StringData

The topic ‘ConvertFrom-String (TemplateContent)’ is closed to new replies.