こんにちは、私は、自分のコマンドレットパラメータの1つの単純なテキストファイルの内容に基づいて動的なValidateSetを作成しようとしています。私はこのブログの記事https://blogs.technet.microsoft.com/pstips/2014/06/09/dynamic-validateset-in-a-dynamic-parameter/に続いて、私は次のを思い付いた:パラメータセット '__AllParameterSets'で動的パラメータを指定できません
function Remove-NetScalerWhiteListItem
{
[CmdletBinding()]
Param
(
)
DynamicParam
{
$ParameterName = "ServiceGroup"
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Mandatory = $true
$ParameterAttribute.Position = 0
$ParameterAttribute.DontShow = $false
$serviceGroups = Get-NetScalerWhiteList
$ValidateSetAtrribute = New-Object System.Management.Automation.ValidateSetAttribute($serviceGroups)
$AttributeCollection.Add($ValidateSetAtrribute)
$RunTimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
$RuntimeParameterDictionary.Add($ParameterName, $RunTimeParameter)
$RuntimeParameterDictionary
}
Begin
{
$ServiceGroup = $PSBoundParameters[$ParameterName]
}
Process
{
Copy-Item "$masterIgnoreFilePath\ingnore.txt" "$masterIgnoreFilePath\ingnore.bak"
$serviceGroups = Get-NetScalerWhiteList
$serviceGroups.Remove($serviceGroup)
Write-Host $serviceGroups
}
}
これは部分的に動作しますが、私はのいずれかを選択しかし、ときに私は、私の検証セットがあるRemove-NetScalerWhiteListItem -ServiceGroup
を入力して作業をすることから始めた場合項目と、私は次のエラーを取得コマンドを実行します。具体的にGet-Content
コール単なるラッパーであるライン$serviceGroups = Get-NetScalerWhiteList
については
Remove-NetScalerWhiteListItem : Parameter 'ServiceGroup' cannot be specified
in parameter set '__AllParameterSets'.
At line:1 char:1
+ Remove-NetScalerWhiteListItem -servicegroup servicegroupname
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-
NetScalerWhiteListItem], ParameterBindingException
+ FullyQualifiedErrorId : ParameterNotInParameterSet,Remove-
NetScalerWhiteListItem
をファイル。
ショーンさん、ありがとうございました!私はそれが私の目の前になければならないと思った –