ValidateRange 属性指定 cmdlet 参数参数的最小值和最大值(范围)。 Windows PowerShell 函数也可以使用此属性。
语法
[ValidateRange(object minRange, object maxRange)]
参数
MinRange
(System.Object) 必需。 指定允许的最小值。
MaxRange
(System.Object) 必需。 指定允许的最大值。
注解
当
MinRange
参数的值大于MaxRange
参数的值时,Windows PowerShell 运行时将引发构造错误。Windows PowerShell 运行时在以下情况下引发验证错误:
当参数的值小于
MinRange
限制或大于MaxRange
限制时。当参数的类型与
MinRange
和MaxRange
参数不同时。
ValidateRange 属性由 System.Management.Automation.ValidateRangeAttribute 类定义。