Custom error from parameters in PowerShell

后端 未结 4 2025
夕颜
夕颜 2020-12-17 14:25

Is it possible to have ValidateScript generate a custom error message when a test fails, like say Test-Path?

Instead of this:

4条回答
  •  悲&欢浪女
    2020-12-17 14:56

    I am not sure.

    A suggestion: maybe you want to just trap the error, and make your own message.

    trap [Error.Type] { 
      @"
      The message you want displayed.
      With maybe some additional information.
      I.e.: The full message itself: {0}' -f  $_.Error.Message;
      continue;
    }
    

提交回复
热议问题