検証セットを作成するのは簡単です。あなたのPowerShellのバージョン>は2 PowershellがValidationSetで自動完成
ある場合は、開始時のparamsに通過しない場合、それはそれほど有用ではないのですが
param(
[Parameter(Mandatory=$true)]
[ValidateSet('Ding','Dong')]
[string]$bellState,
[Parameter(Mandatory=$true)]
[ValidateSet('Dead','Alive')]
[string]$witchesState
)
無料の自動補完を提供します。
cmdlet Untitled2.ps1 at command pipeline position 1
Supply values for the following parameters:
bellState: Dib
witchesState: Alive
C:\Users\cac\Untitled2.ps1 : Cannot validate argument on parameter 'bellState'. The argument "Dib" does not belong to the set "Ding,Dong" specified by the ValidateSet attribute. Supply an argument that is in the set and then
try the command again.
+ CategoryInfo : InvalidData: (:) [Untitled2.ps1], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Untitled2.ps1
今回全くタブ補完や手がかりがない:(
無効な何かを入力すると、あなたが有益なエラーを取得する実行します。
"The argument "Dib" does not belong to the set "Ding,Dong""
しかし、このエラーが最後にスローされます元の間違いの時ではなく、再試行するオプションはありません。
この検証を拡張して、ユーザーフレンドリーになる方法が見つかったことはありますかパラメータで渡されずに開始されたインスタンス
があります。私がうまくいくことがわかっているのは、 'Read-Host'コマンドレットを使って自分でやることですが、私はそれをあなたに勧めません。あなたはおそらくそれと一緒に暮らすべきです。 –