ProcessModule() display a message if action does not exist

This commit is contained in:
Yorick Barbanneau 2018-03-25 21:14:03 +02:00
parent c2733d133c
commit 27614e531d

View file

@ -486,18 +486,27 @@ function ProcessModuleFile {
foreach( $p in $_.psobject.properties.name ){ foreach( $p in $_.psobject.properties.name ){
$current_action[$p] = $_.$p $current_action[$p] = $_.$p
} }
if ( -not $current_action.ContainsKey('action') ) {
Write-Host -ForegroundColor Red "`tError : action not found"
return
}
# If action content a file element, need to test if file exist # If action content a file element, need to test if file exist
if ( $current_action.ContainsKey('file')) { if ( $current_action.ContainsKey('file')) {
$action_file = $(Get-ChildItem $path).DirectoryName + "\" + $(Get-ChildItem $path).BaseName + "\" + $current_action.file $action_file = $(Get-ChildItem $path).DirectoryName + "\" + $(Get-ChildItem $path).BaseName + "\" + $current_action.file
if ( -not (Test-Path $action_file) ) { if ( -not (Test-Path $action_file) ) {
Write-Host -ForegroundColor Red "`tError in $($mod.name) : file $action_file not found" Write-Host -ForegroundColor Red "`tError in $($mod.name) : file $action_file not found`n"
return return
} }
$current_action.file = $action_file $current_action.file = $action_file
} }
# Invoke function # Invoke function
if (Get-Command $($_.action) -ErrorAction SilentlyContinue ){
Invoke-Expression "$($_.action) `$current_action" Invoke-Expression "$($_.action) `$current_action"
} }
else {
Write-Host -ForegroundColor Red "`tError in $($mod.name) : action $($_.action) not exist"
}
}
} }
Write-Output "`nIt's time to kick ass and chew bubble gum" Write-Output "`nIt's time to kick ass and chew bubble gum"