I find the standard Powershell display of errors (red text, multi-line display) a bit distracting. Is it possible to customize this?
I find the standard Powershell display of errors (red text, multi-line display) a bit
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes and yes.
You can use the built-in
$hostobject if all you want to do is change the text color. However, you can’t change the error message itself – that’s hardcoded.What you could do is (a) suppress the error messages, and instead (b) trap the errors and display your own.
Accomplish (a) by setting
$ErrorActionPreference = 'SilentlyContinue'– this won’t STOP the error, but it suppresses the messages.Accomplishing (b) requires a bit more work. By default, most PowerShell commands don’t produce a trappable exception. So you’ll have to learn to run commands and add the -EA ‘Stop’ parameter to generate a trappable exception if something goes wrong. Once you’ve done that, you can create a trap in the shell by typing:
You could put this in your profile script rather than typing it every time. Inside the trap, you can output whatever error text you like by using the Write-Error cmdlet.
Probably more work than you were wanting to do, but that’s basically how you’d do what you asked.