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

 
Participant
3 months ago.

  • Author
    Posts
  • #110851

    Participant
    Points: 0
    Rank: Member

    Hi,

    I would like to extract the following data:

    • UserStateRunning IE:ProtectedMode
    • Doc:ProtectedMode
    • vSentry:Enabled
    • stage1: Stage1Image0001
    • stage2: Stage2Image0001
    • locationPath: C:\ProgramData\Bromium\vSentry\4.1.1.1974\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\4.1.1.1974\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

    Keymaster
    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

    Participant
    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.

    https://powershell.org/forums/topic/need-to-read-a-file-and-store-it-in-a-variable/#post-91695

  • #111454

    Participant
    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.