MetadataError: The attribute cannot be added because variable Message with value bye would no longer be valid. 使用ValidateSet 也會啟用該參數值的索引標籤展開。 如需詳細資訊,請參閱 about_Tab_Expansion。使用類別的動態 ValidateSet 值您可以使用 類別,在運行時間動態產生 ValidateSet 的值。 在下列範例中...
12.3.17 ValidateSet 属性 此属性用于 脚本参数 或变量 指定参数参数的一组有效值。 以下参数用于定义参数的特征: 展开表 参数名称 用途 ValidValues(位置 0) 类型:string[] 有效值集。 IgnoreCase(已命名) 类型:bool;默认值:$true 指定字符串类型的参数是否应忽略大小写。 如果参数具有数组类型,则相应参数数组...
FunctionSet-Prompt41{42param(43[Parameter(Mandatory=$true)]44[ValidateSet('Normal','Cmd','Arrow','Simple', 'None',IgnoreCase =$true)]45$Mode46)47$varPSPromptMode= (Get-Variable'PSPromptMode' -ErrorAction SilentlyContinue)48#配置变量不存在则新建49if($varPSPromptMode-eq$null)50{51New-Variab...
[validateset('User','Machine','U','M','Detail','D','Combin','C')] $Scope='C' ) $res=Get-EnvList-Scope$Scope|Where-Object{$_.Name-like$Key} #统计环境变量个数 $res=Format-EnvItemNumber-EnvVars$res-Scope # Write-Output $res return$res } 例 .EXAMPLE 🚀 get-EnvVar -scope U ...
In this example, we use the VpnGw2, Generation 2 SKU. If you see ValidateSet errors regarding the GatewaySKU value and are running these commands locally, verify that you have installed thelatest version of the PowerShell cmdlets. The latest version contains the new validated values for the ...
enum TopicListType { Suggested Confirmed Published Removed All }functionGetMicroserviceUrlByEnvironment {param( [ValidateSet("Prod","GCC")] [Parameter(Mandatory =$true, ParameterSetName)] [string]$Environment, [ValidateSet("Live","Staging")] [string]$Pipeline="Live")$msBase="km"$substrateRegion...
ValidateSet和交换机参数 我有一个带有两个开关参数的Powershell函数。这些开关不能一起使用,只能使用其中的一个。 有没有办法验证这个场景,并防止两者一起使用? 浏览0提问于2018-04-10得票数0 1回答 Powershell-从变量调用子函数 、、 如何在PowerShell中调用函数的子集?我尝试过使用开关,但它需要传入一个开关...
It is better to collapse the two switches into one parameter which can take any of the three values with a default, like this. function Send-Message { param( [string] $Message, [ValidateSet('Normal','High','Low')]$Priority = 'High' ) Switch ($Priority) { "Low" {Invoke-...
[ValidateSet("Data","Log")] [Parameter(Position=1,Mandatory=$true)][string]$dirtype ) This second param section uses ValidateScript to check that the input object namespace is an SMO object. param([Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][ValidateScript({$_.GetType()...
[ValidateSet] [ValidateTrustedData] [ValidateUserDrive] [version] [void] [WildcardPattern] [wmi] (Windows-only) [wmiclass] (Windows-only) [wmisearcher] (Windows-only) [X500DistinguishedName] [X509Certificate] [xml] Only the following COM object types are permitted: Scripting.Dictionary Scripting...