Validating Parameter Input
PowerShell can validate the arguments passed to cmdlet parameters in several ways. PowerShell can validate the length, the range, and the pattern of the characters of the argument. It can validate the number of arguments available (the count). These validation rules are defined by validation attributes that are declared with the Parameter attribute on public properties of the cmdlet class.
To validate a parameter argument, the PowerShell runtime uses the information provided by the validation attributes to confirm the value of the parameter before the cmdlet is run. If the parameter input is not valid, the user receives an error message. Each validation parameter defines a validation rule that is enforced by PowerShell.
PowerShell enforces the validation rules based on the following attributes.
ValidateCount
Specifies the minimum and maximum number of arguments that a parameter can accept. For more information, see ValidateCount Attribute Declaration.
ValidateLength
Specifies the minimum and maximum number of characters in the parameter argument. For more information, see ValidateLength Attribute Declaration.
ValidatePattern
Specifies a regular expression that validates the parameter argument. For more information, see ValidatePattern Attribute Declaration.
ValidateRange
Specifies the minimum and maximum values of the parameter argument. For more information, see ValidateRange Attribute Declaration.
ValidateScript
Specifies the valid values for the parameter argument. For more information, see ValidateScript Attribute Declaration.
ValidateSet
Specifies the valid values for the parameter argument. For more information, see ValidateSet Attribute Declaration.
See Also
PowerShell
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示