0

I'm trying to exclude a few properties from Azure's CLI Output. I know I can use --query to filter through the output using its JMESPath. But I want to exclude just one of them, so it doesn't make sense to select all the other using --query.

Is there a way to do this? I'm looking for something similar to what PowerShell can do:

Select-Object -Property * -ExcludeProperty

The following example illustrates one particular case.

Sample Command: az ad group list -o json

Output:

[
 {
    "deletionTimestamp": null,
    "description": "app_description",
    "dirSyncEnabled": null,
    "displayName": "name",
    "lastDirSyncTime": null,
    "mail": "sample@domain.com",
    "mailEnabled": true,
    "mailNickname": "sampleMail",
    "objectId": "xxxxxx-xxxx-xxxxxxxx-xxxxx",
    "objectType": null,
    "onPremisesDomainName": null,
    "onPremisesNetBiosName": null,
    "onPremisesSamAccountName": null,
    "onPremisesSecurityIdentifier": null,
    "provisioningErrors": [],
    "proxyAddresses": [],
    "securityEnabled": false
  }
]

Expected Output: Same as above, but without the description and objectId properties.

QuantAC
  • 31
  • 1
  • 9

1 Answers1

1

JMESPath doesn't support removing properties/keys as of today. This ask has been open for a while now: Ability to set and delete based on a jmespath #121

As mentioned in the linked GitHub issue, one workaround would be to pipe the output ($json) to jq:

echo $json | jq 'del(.[0].objectId, .[0].description)'

that would produce the following output excluding objectId and description:

[
  {
    "deletionTimestamp": null,
    "dirSyncEnabled": null,
    "displayName": "name",
    "lastDirSyncTime": null,
    "mail": "sample@domain.com",
    "mailEnabled": true,
    "mailNickname": "sampleMail",
    "objectType": null,
    "onPremisesDomainName": null,
    "onPremisesNetBiosName": null,
    "onPremisesSamAccountName": null,
    "onPremisesSecurityIdentifier": null,
    "provisioningErrors": [],
    "proxyAddresses": [],
    "securityEnabled": false
  }
]
Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30