ValidateScript Attribute Declaration
The ValidateScript
attribute specifies a script that's used to validate a parameter or variable
value. PowerShell pipes the value to the script, and generates an error if the script returns
$false
or if the script throws an exception.
When you use the ValidateScript
attribute, the value that's being validated is mapped to the $_
variable. You can use the $_
variable to refer to the value in the script.
Syntax
[ValidateScriptAttribute(ScriptBlock scriptBlock)]
[ValidateScriptAttribute(ScriptBlock scriptBlock, Named Parameters)]
Parameters
scriptBlock
- (System.Management.Automation.ScriptBlock) Required. The script block used to validate the input.ErrorMessage
- Optional named parameter - The item being validated and the validating scriptblock are passed as the first and second formatting arguments.
Note
The ErrorMessage
argument was added in PowerShell 6.
Remarks
- This attribute can be used only once per parameter.
- If this attribute is applied to a collection, each element in the collection must match the pattern.
- The ValidateScript attribute is defined by the System.Management.Automation.ValidateScriptAttribute class.
See Also
Dolgozzon együtt velünk a GitHubon
A tartalom forrása a GitHubon található, ahol létrehozhat és áttekinthet problémákat és lekéréses kérelmeket is. További információért tekintse meg a közreműködői útmutatónkat.
Visszajelzés
https://aka.ms/ContentUserFeedback.
Hamarosan elérhető: 2024-ben fokozatosan kivezetjük a GitHub-problémákat a tartalom visszajelzési mechanizmusaként, és lecseréljük egy új visszajelzési rendszerre. További információ:Visszajelzés küldése és megtekintése a következőhöz: