Skip to content

Instantly share code, notes, and snippets.

@SteveL-MSFT
Created March 19, 2024 20:43
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 SteveL-MSFT/f0356bc00a249bd790564d8a73d53f6b to your computer and use it in GitHub Desktop.
Save SteveL-MSFT/f0356bc00a249bd790564d8a73d53f6b to your computer and use it in GitHub Desktop.
$ExecutionContext.InvokeCommand.CommandNotFoundAction =
{
param(
[string]
$commandName,
[System.Management.Automation.CommandLookupEventArgs]
$eventArgs
)
Write-Warning "Command $commandName was not found."
# populate a command otherwise you'll also get the normal command not found error
# note that the command you're replacing here will be executed, so using `Select-Object`
# which will quietly exit
$eventArgs.Command = (Get-Command Select-Object)
# stop searching
$eventArgs.StopSearch = $True
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment