I'm trying to use Select-String in PowerShell to look at the results from docker inspect command, but the Context property doesn't seem to be working properly.
As you know, docker inspect returns normal JSON as output, e.g.:
[
{
"Id": "c8a5810c62d8dbea11335be561522b4a3df53b9ddcae5531ae06483926c5f992",
"Created": "2018-07-31T17:16:53.8689464Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 13613,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-07-31T17:16:54.6460418Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
...
},
...
]
Running sls (alias for Select-String) without any additional arguments:
And running it with Context:
As you can see, the output is the same, and I don't see the before and after lines in my output
I'm able to use grep to do what I want; e.g.,
docker inspect devtest | grep Mounts -B 5 -A 5
Output of grep:
But I was wondering why Select-String doesn't work.
Update
As @iRon suggested, I even tried saving the output to a file and then use Select-String on the file (sample file):
So, I'm really confused as to what's happening. Because for @iRon it's working properly.
Update 2
I noticed that if I do something like this:
$result = $json | Select-String "Mounts" -Context 5`
then when I look at $result[0].Context.PreContext (and PostContext), they contain the before and after lines in the input, but for some unknown reason, they're not printed to the console




docker inspectcommand. As you see it's normal JSON, but I don't want to parse JSON and all that; I just want to useSelect-Stringand be able to see theContextmountin thedocker inspectoutput example, especially knowing you do not want to parse it with a simple cmdlet asConvertFro-JsonConvertFrom-Json, but the thing is that I don't know exactly whereMountsis in the hierarchy, so I thoughtSelect-Stringwould help, but my problem is that theContextproperty doesn't work here! If you check the screenshot I included forgrep, you can seeMounts(I just copy pasted a few lines for brevity and to only show the shape of the output)