read file line as hashtable

Welcome Forums General PowerShell Q&A read file line as hashtable

Viewing 2 reply threads
  • Author
    Posts
    • #189949
      Participant
      Topics: 21
      Replies: 32
      Points: 309
      Rank: Contributor

      hi all,

      another noob question, please

      I have a list of files I have to check if some value is present. Each line on these files are in a format like;
      <p style=”padding-left: 40px;”>Name1=nameHere Value=</p>
      <p style=”padding-left: 40px;”>Name2=nameHere Value=someValue</p>
      Value could be either empty or not.

      my question is: how can I read each line and place it in a hashtable, so then I can do if ($hash.Value -ne ”) …

      thank you!

    • #189958
      Participant
      Topics: 2
      Replies: 513
      Points: 1,322
      Helping Hand
      Rank: Community Hero

      You could use a bit of regex parsing on each line, I suppose.

      https://gist.github.com/vexx32/824cb519f6cc6d0f3486233753362919

      But it will depend a lot on the format of your file and how consistent it is.

    • #189973
      Participant
      Topics: 21
      Replies: 32
      Points: 309
      Rank: Contributor

      it’s perfect.

      thanks!

Viewing 2 reply threads
  • The topic ‘read file line as hashtable’ is closed to new replies.