Data
Data for the example:
$json = @"
[
{
"DATE": "2022-01-05",
"WALCL": "8765721.0"
},
{
"DATE": "2022-01-12",
"WALCL": "8788278.0"
},
{
"DATE": "2022-01-19",
"WALCL": "8867834.0"
},
{
"DATE": "2022-01-26",
"WALCL": "8860485.0"
},
{
"DATE": "2022-02-02",
"WALCL": "8873211.0"
}
]
"@
Example : works as expected
Display a single item:
$cde = $json | ConvertFrom-Json
$cde | Select-Object -First 1
Result:
DATE WALCL
---- -----
2022-01-05 8765721.0
OK, this works as expected.
Example : different behavior
Similar code without the temporary variable:
$json | ConvertFrom-Json | Select-Object -First 1
It does not display a single line this time, but all of them:
DATE WALCL
---- -----
2022-01-05 8765721.0
2022-01-12 8788278.0
2022-01-19 8867834.0
2022-01-26 8860485.0
2022-02-02 8873211.0
Question
Why does the version without the temporary variable return multiple lines despite the Select-Object -First 1
?