27 lines
592 B
PowerShell
27 lines
592 B
PowerShell
|
function Invoke-Hook() {
|
||
|
param(
|
||
|
[string] $Name,
|
||
|
[System.Action] $Fallback
|
||
|
)
|
||
|
|
||
|
if ($Fallback) {
|
||
|
$scriptBlock = { $Fallback.Invoke(); };
|
||
|
} else {
|
||
|
$scriptBlock = { };
|
||
|
}
|
||
|
|
||
|
if (Get-Command "$Name" -ErrorAction SilentlyContinue) {
|
||
|
$parameters = {
|
||
|
fallback = $scriptBlock
|
||
|
};
|
||
|
|
||
|
Write-Host "Running Hook ``$Name``";
|
||
|
& "$Name" @parameters;
|
||
|
} elseif ($Fallback) {
|
||
|
Write-Host "Running Default of Hook ``$Name``";
|
||
|
& $scriptBlock;
|
||
|
} else {
|
||
|
Write-Host "Hook ``$Name``";
|
||
|
}
|
||
|
}
|