Dichiarazione dell'attributo ValidateLengthValidateLength Attribute Declaration
L'attributo ValidateLength specifica il numero minimo e massimo di caratteri per un argomento di parametro del cmdlet.The ValidateLength attribute specifies the minimum and maximum number of characters for a cmdlet parameter argument. Questo attributo può essere usato anche dalle funzioni di Windows PowerShell.This attribute can also be used by Windows PowerShell functions.
SintassiSyntax
[ValidateLength(int minLength, int maxlength)]
ParametriParameters
MinLength
(System. Int32) obbligatorio.MinLength
(System.Int32) Required. Specifica il numero minimo di caratteri consentiti.Specifies the minimum number of characters allowed.
MaxLength
(System. Int32) obbligatorio.MaxLength
(System.Int32) Required. Specifica il numero massimo di caratteri consentiti.Specifies the maximum number of characters allowed.
CommentiRemarks
Per ulteriori informazioni su come dichiarare questo attributo, vedere How to declare input validation rules.For more information about how to declare this attribute, see How to Declare Input Validation Rules.
Quando questo attributo non viene utilizzato, l'argomento del parametro corrispondente può essere di qualsiasi lunghezza.When this attribute is not used, the corresponding parameter argument can be of any length.
Il runtime di Windows PowerShell genera un errore nelle condizioni seguenti:The Windows PowerShell runtime throws an error under the following conditions:
Se il valore del
MaxLength
parametro dell'attributo è minore del valore del parametro dell'MinLength
attributo.When the value of theMaxLength
attribute parameter is less than the value of theMinLength
attribute parameter.Quando il
MaxLength
parametro dell'attributo è impostato su 0.When theMaxLength
attribute parameter is set to 0.Quando l'argomento non è una stringa.When the argument is not a string.
L'attributo ValidateLength è definito dalla classe System. Management. Automation. Validatelengthattribute .The ValidateLength attribute is defined by the System.Management.Automation.Validatelengthattribute class.
Vedere ancheSee Also
Scrittura di un cmdlet di Windows PowerShellWriting a Windows PowerShell Cmdlet