Parsing json with unnamed array #1131
-
I am trying to do PSRule validation on below json file, which is having an unnamed array with 3 elements. I am looking to fetch the value of field 'RoleDefinitionName' of the first element only and validate its value. I tried using this expression but its returning me value from all three child elements. How can we handle this unnamed array for fetching a particular value. Any help or suggestion would be highly appreciated. Thankyou. $ActualValue = $TargetObject.RoleDefinitionName [ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@ankur90Git By default rules run against all input objects, however you can use conditions to limit which objects that apply to by configuring a pre-condition. When set, rules will only apply to objects that return For a single rule, the easiest way would be to use a script pre-condition, like this: # Synopsis: An example script rule with pre-conditions.
Rule 'AppConfigurationPermission' -If { $TargetObject.RoleDefinitionName -eq 'App Configuration Data Reader' } {
# Rule condition
} While the other objects would still be discovered, the rule will only run against the first object. Which is probably what you want because there may be other rules for the other objects. You can disable the warning generated for objects not matching any rules by setting Execution.NotProcessedWarning. There are some more detail here: Using pre-conditions I hope that helps. |
Beta Was this translation helpful? Give feedback.
-
Thankyou so much for answering my question. Your answer helped me in solving my problem. |
Beta Was this translation helpful? Give feedback.
@ankur90Git By default rules run against all input objects, however you can use conditions to limit which objects that apply to by configuring a pre-condition. When set, rules will only apply to objects that return
$true
for the pre-condition.For a single rule, the easiest way would be to use a script pre-condition, like this:
While the other objects would still be discovered, the rule will only run against the first object. Which is probably what you want because there may be other rules for the ot…