Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active March 14, 2019 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/e7740b3885eb6296a26b5f7f82a17c9a to your computer and use it in GitHub Desktop.
Save IISResetMe/e7740b3885eb6296a26b5f7f82a17c9a to your computer and use it in GitHub Desktop.
Hijack a subset of non-existing commands in PowerShell
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param([string]$CommandName, [System.Management.Automation.CommandLookupEventArgs]$evtArgs)
if($CommandName -like '*glue*'){
$evtArgs.CommandScriptBlock = {
Write-Host "Eating glue because of $CommandName ..." -ForegroundColor Green
}.GetNewClosure()
$evtArgs.StopSearch = $true
}
}
Get-GlueStuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment