Using convertfrom-json to search for records in json formatted file

Welcome Forums General PowerShell Q&A Using convertfrom-json to search for records in json formatted file

Viewing 1 reply thread
  • Author
    Posts
    • #268661
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      hi out there

      I am newbie to powershell and have always used shell or awk in linux to solve scripting – but now I want to get it done in powershell instead since this is my native working platform

      I have a small problem here when I am trying to use converfrom-json to get the access to the different records in a json formatted string – ex:

      $x = Get-content -path c:\temp\file.json | convertfrom-json
      $x | ForEach-Object {

      f ( $x.model -Match “MY” ) {
      Write-Host $x.model, $x.publicip }
      }

      the records look f.ex like this:

      mac : ac:17:c8:3b:e5:b0
      networkId :
      model : MY225
      publicIp : 1.2.3.4

      mac : ac:17:c8:3b:ec:78
      networkId :
      model : MS225
      publicIp : 1.2.3.5

      To print model and publicip – how should the script look just to give me some starting hints?

      br tiwang

    • #268892
      Participant
      Topics: 16
      Replies: 1855
      Points: 3,568
      Helping Hand
      Rank: Community Hero

      Using -match is a regex expression. To do a simple wildcard search, you can use -like.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.