Param( [ValidateSet('hello', 'world')] [string]$Message ) $Message = 'bye' 這個範例會在執行時間傳回下列錯誤: 複製 MetadataError: The attribute cannot be added because variable Message with value bye would no longer be valid. 如需索引標籤展開的詳細資訊,請參閱 about_Tab_Expansion...
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属性为参数或变量指定一组有效值。 如果参数或变量值与集中的值不匹配,PowerShell 将生成错误。 在以下示例中,Detail参数的值只能为 Low、Average 或 High。 PowerShell Param( [Parameter(Mandatory=$true)] [ValidateSet("Low","Average","High")] [String[]...
想要获取实例的话,可以在powershell中运行命令:get-help New-Variable -examples new-variable 实例(以下列出一部分): # 创建一个变量:dayNew-Variabledays# 创建一个变量:zipcode,且赋值为 98033New-Variable-Name"zipcode"-Value98033# 创建一个只读型的变量New-Variable-NameMax-Value256-OptionReadOnly# 该变量...
從PowerShell 7.0 開始,已針對 指派給變數時 的值ValidateSet新增索引標籤展開。 例如,如果您輸入下列變數定義: PowerShell [ValidateSet('Chocolate','Strawberry','Vanilla')] [string]$flavor='Strawberry'$flavor= <tab> 當您叫用Tab鍵時,會收到下列結果: ...
12.3.17 The ValidateSet attribute This attribute is used in a script-parameter or variable to specify a set of valid values for the argument of the parameter. The following arguments are used to define the characteristics of the parameter: Expand table Parameter NamePurpose ValidValues (position...
为什么不让PowerShell验证参数$TypeAdressage始终是两个(或更多)预定义字符串之一? function Changer-Type { param( [string]$Identifiant, [ValidateSet('Dynamique','Statique')] [string]$TypeAdressage, [string]$Path ) if(-not(Test-Path $Path -PathType Leaf) -or [IO.Path]::GetExtension($Path) -...
[ValidateSet('Machine', 'User')] $Scope = 'User', [switch]$V, [switch]$Query ) # 同步环境变量 Update-EnvVar -Scope $Scope # 先获取当前用户或机器级别的 环境变量 值 $current_value = [Environment]::GetEnvironmentVariable($env_var, $Scope) ...
为什么不让PowerShell验证参数$TypeAdressage始终是两个(或更多)预定义字符串之一? function Changer-Type { param( [string]$Identifiant, [ValidateSet('Dynamique','Statique')] [string]$TypeAdressage, [string]$Path ) if(-not(Test-Path $Path -PathType Leaf) -or [IO.Path]::GetExtension($Path) -...
[Parameter(ValueFromPipeline=$true, Mandatory=$true)] [Alias('name')] [string]$siteName, [ValidateSet(3000,5000,8000)] [int]$port = 3000 ) BEGIN { Write-Verbose 'Creating new website(s)' } PROCESS { echo "name: $siteName, port: $port" } ...