Ask Your Question
4

What is the solution to prevent populating `$Error` in Powershell due to casting error?

asked 2022-03-28 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-06-18 23:00:00 +0000

plato gravatar image

One way to prevent populating $Error in Powershell due to casting error is to use the -ErrorAction SilentlyContinue parameter in your command. This will suppress the error message from being displayed on the console and prevent it from populating $Error. Another way is to use a try-catch block to handle the potential casting error and prevent it from propagating up to $Error.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-03-28 11:00:00 +0000

Seen: 7 times

Last updated: Jun 18 '22