ValidateRange 属性声明

ValidateRange 属性指定 cmdlet 参数参数的最小值和最大值(范围)。 Windows PowerShell 函数也可以使用此属性。

语法

[ValidateRange(object minRange, object maxRange)]

参数

MinRangeSystem.Object) 必需。 指定允许的最小值。

MaxRangeSystem.Object) 必需。 指定允许的最大值。

注解

  • MinRange 参数的值大于 MaxRange 参数的值时,Windows PowerShell 运行时将引发构造错误。

  • Windows PowerShell 运行时在以下情况下引发验证错误:

    • 当参数的值小于 MinRange 限制或大于 MaxRange 限制时。

    • 当参数的类型与 MinRangeMaxRange 参数不同时。

  • ValidateRange 属性由 System.Management.Automation.ValidateRangeAttribute 类定义。

另请参阅

System.Management.Automation.ValidateRangeAttribute

编写 Windows PowerShell Cmdlet