Skip to content

Using $Assert and/or PSRule expressions in Conventions #3316

Answered by BernieWhite
eosfor asked this question in Q&A
Discussion options

You must be logged in to vote

@eosfor Convention lifecycle is covered here: https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Conventions/ and $Assert is covered here: https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Variables/#assert.

In short, assertion is intended to be run within a rule, because it controls the pass or fail of a rule. So, you are correct $Assert is not available within a convention, or at other times.

You can generate errors in conventions, but they are treated as errors instead of a rule failure. Throw is one way, also Write-Error.

Within a convention -Initialize and -Begin blocks you can create new custom objects that will be processed by the pipeline.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by eosfor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants