2024-07-30 16:34:19 +00:00
|
|
|
function Invoke-Hook() {
|
|
|
|
param(
|
|
|
|
[string] $Name,
|
2024-07-31 20:18:47 +00:00
|
|
|
[scriptblock] $Fallback
|
2024-07-30 16:34:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if ($Fallback) {
|
2024-07-31 20:18:47 +00:00
|
|
|
$scriptBlock = $Fallback;
|
2024-07-30 16:34:19 +00:00
|
|
|
} 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``";
|
|
|
|
}
|
|
|
|
}
|