microsoft / PSRule

Validate infrastructure as code (IaC) and objects using PowerShell rules.
https://microsoft.github.io/PSRule/v2/
MIT License
376 stars 49 forks source link

[Question] About OutCome and OutComeReason #195

Closed LaurentDardenne closed 5 years ago

LaurentDardenne commented 5 years ago

I'm trying to list the different results that Invoke-PSRule can return, but some cases (enum RuleOutcomeReason) seem to me not to be generated:

$Path='C:\temp'
$File='Test.Rule.ps1'
@'
Rule Test -if {$true} {
 $true
}

Rule Test1 -if {$true} {
    $false
}

Rule Test2 -if {$true} {

}

Rule Test3 -if {$false} {

}

Rule Test4 -if {} {

}

Rule Test5 -if {$null} {

}

Rule Test6  {
  1/0
}

Rule 'WithDependency2' -DependsOn 'WithDependency5' {
    # Pass
    $True;
}

# Synopsis: Fail
Rule 'WithDependency5' {
    # Fail
    $False
}
'@ >"$Path\$File"
$Result='object'|Invoke-PSRule -path "$Path\$File" 
$Result|Select-Object RuleName,Outcome,OutcomeReason
# RuleName        Outcome OutcomeReason
# --------        ------- -------------
# Test               Pass     Processed
# Test1              Fail     Processed
# Test2              Fail  Inconclusive
# WithDependency5    Fail     Processed

I read that some are skipped but we do not know it in the end result. And I can not find those in error unless parsing the $Error collection or those 'DependencyFail' or 'PreconditionFail' unless they are internal states.

BernieWhite commented 5 years ago

@LaurentDardenne Rules skipped due to preconditions haven't be executed so the outcome is None which is filtered by default.

Try adding -Outcome All.

LaurentDardenne commented 5 years ago

Thank you.