[ValidateScript({ If ($_ -gt10) { throw'You have submitted a value greater than 10. That will not work, dummy!' } Elseif ($_ -lt1) { throw'You have submitted a value lower than 1. That will not work, dummy!' }
PS C:\> $test2 = 11 You have submitted a value greater than 10. That will not work, dummy! At line:5 char:3 + { throw'You have submitted a value greater than 10. That will not work, dummy ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (You have submitted a...not work, dummy!:String ) [], RuntimeException + FullyQualifiedErrorId : You have submitted a value greater than 10. That will not work, dummy! PS C:\> $test2 = -2 You have submitted a value lower than 1. That will not work, dummy! At line:7 char:3 + { throw 'You have submitted a value lower than 1. That will not work, dummy ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (You have submitted a...not work, dummy!:String ) [], RuntimeException + FullyQualifiedErrorId : You have submitted a value lower than 1. That will not work, dummy!
Here is an example – these lines both produce a FileInfo object which represents the exact same file. Only the way how the object was created is different. All object properties are identical. Yet, ToString() differs: 以下是一个例子——这两行代码都会创建一个 FileInfo 对象,来代表同一个文件。只是创建对象的方法有所不同。所有的对象属性都相同。然而,ToString() 的结果不同: