PortValhalla/scripts/Windows/Scripts/Hooks.ps1
2024-10-06 21:25:34 +02:00

27 lines
577 B
PowerShell

function Invoke-Hook() {
param(
[string] $Name,
[scriptblock] $Fallback
)
if ($Fallback) {
$scriptBlock = $Fallback;
} 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``";
}
}