I have a nested set of data that I am trying to get a nested value to evaluate with the where-object clause that looks like:
$configs | Where-Object {$_.data.attributes.property -eq 'value'}
I have learnt that nested objects don't work like this.
I have tried doing nested select statements like:
($configs | Where-Object {($_.data | select attributes | select 'property') -eq 'value'})
And tried using the in memory where() function like this:
$configs.where({$_.data.where{$_.attributes.where{$_.'property' -ne 'value'}}})
These don't return no data as I would have expected from an invalid script block, but they will return all data with no filtering, even if I change -eq to -ne it returns the same thing.
$configs.data.attributes | ?{$_.property -eq 'value'}
returns the list of what I would expect, but I need the output to include the data from the base $config
variable, not just the data in the attributes nested object.
How can I use the where-object clause on a nested object property?
Sample data of $config:
{
"data": [
{
"id": "12345678",
"type": "configurations",
"attributes": {
"organization-id": 1234657,
"organization-name": "organization",
"resource-url": "https://subdomain.domain.com/1234567/item/12345678",
"restricted": false,
"psa-integration": "enabled",
"my-glue": false,
"name": "Simple Switch01",
"hostname": null,
"primary-ip": null,
"mac-address": null,
"default-gateway": null,
"serial-number": null,
"asset-tag": null,
"position": null,
"installed-by": null,
"purchased-by": null,
"notes": null,
"operating-system-notes": null,
"warranty-expires-at": null,
"installed-at": null,
"purchased-at": null,
"created-at": "2017-10-20T03:01:20Z",
"updated-at": "2022-03-12T07:05:39Z",
"organization-short-name": "organization",
"configuration-type-id": 193614,
"configuration-type-name": "Managed Switch",
"configuration-type-kind": "switch",
"configuration-status-id": 13313,
"configuration-status-name": "Active",
"manufacturer-id": null,
"manufacturer-name": null,
"model-id": null,
"operating-system-id": null,
"operating-system-name": null,
"location-id": 3134450,
"location-name": "Lower Hutt",
"contact-id": 7683204,
"archived": false,
"model-name": null,
"contact-name": "name"
},
"relationships": {
"adapters-resources": {
"data": [
"@{id=617978337; type=adapters_resources}"
]
},
"passwords": {
"data": []
},
"attachments": {
"data": []
}
}
}
],
"included": [],
"meta": {
"current-page": 1,
"next-page": 2,
"prev-page": null,
"total-pages": 8482,
"total-count": 8482,
"filters": {}
},
"links": {
"self": "self link",
"next": "next link",
"last": "last link"
}
}