Created
March 19, 2024 20:43
-
-
Save SteveL-MSFT/f0356bc00a249bd790564d8a73d53f6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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