Better pswh module validation

This commit is contained in:
Gabo 2020-10-30 14:16:21 -05:00
parent da41dfe6fb
commit 87036c3987

View file

@ -210,36 +210,16 @@ function GetValidationInfo() {
#### Function ValidatePowershellModules ########################################
function ValidatePowershellModules() {
VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1)
# If module found, ensure Invoke-ScriptAnalyzer command is available
if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]]; then
VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1)
else
fatal "Failed to find module."
fi
#########################################
# validate we found the script analyzer #
#########################################
if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then
fatal "Failed to find module."
fi
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Failed
error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!"
fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]"
else
# If module found, ensure Invoke-ScriptAnalyzer command is available
if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]] && [[ ${VALIDATE_PSSA_CMD} == "Invoke-ScriptAnalyzer" ]]; then
# Success
debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system"
debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system"
else
# Failed
error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!"
fatal "[PSSA_MODULE: ${VALIDATE_PSSA_MODULE}] [PSSA_CMD: ${VALIDATE_PSSA_CMD}]"
fi
}
################################################################################