Reputation: 5157
I'm calling a REST api in PowerShell and it is returning some JSON
$records = Invoke-RestMethod $uri -Headers $headers
If I use the .data
attribute, I'm getting what I assume is a PowerShell array object, because I can examine $records.data.count
and I get the expected number of records. Examining one of those records, eg $records.data[5]
id : 123
zone_id : example.com
parent_id :
name : z1
content : 1.2.3.4
ttl : 3600
priority :
type : A
regions : {global}
system_record : False
created_at : 2015-01-10T02:33:46Z
updated_at : 2015-01-10T02:33:46Z
I want to get all of the records where type is A. I've tried $records.data.Where($_.type -eq 'A')
but that is giving me a type exception. What query should I use to filter based upon attribute values?
Upvotes: 2
Views: 1907
Reputation: 174485
I've tried
$records.data.Where($_.type -eq 'A')
but that is giving me a type exception.
The Where()
extension method takes a ScriptBlock
as its first argument (notice the curly braces):
$records.data.Where({$_.type -eq 'A'})
Upvotes: 2