Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 找不到接受参数';t';_Powershell_Syntax_Parameter Passing - Fatal编程技术网

Powershell 找不到接受参数';t';

Powershell 找不到接受参数';t';,powershell,syntax,parameter-passing,Powershell,Syntax,Parameter Passing,我得到以下错误 New-AzResourceGroup : A positional parameter cannot be found that accepts argument 't'. At line:1 char:1 + New-AzResourceGroup -Name @rgName -Location @location -Tag @{LoB="pla ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

我得到以下错误

New-AzResourceGroup : A positional parameter cannot be found that accepts argument 't'.
At line:1 char:1
+ New-AzResourceGroup -Name @rgName -Location @location -Tag @{LoB="pla ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [New-AzResourceGroup], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGrou
pCmdlet
尝试使用以下代码创建新的资源组时。问题在哪里

$rgName = "storage-dev-rg"
$location = "eastus"
New-AzResourceGroup -Name @rgName -Location @location -Tag @{LoB="platform"; CostCenter="IT"}

我想出来了。声明的变量应使用
$
引用,而不是使用
@

引用:

声明的变量应使用
$
引用,而不是使用
@
引用

说明为了在PowerShell中创建变量和以后的引用变量,在这两种情况下都使用sigil
$
作为其名称的前缀;i、 例如,在您的案例中,
$rgName
$location

如果要执行splatting,只能在变量名前面加上sigil
@
(请参阅)

(sigil
@
还有其他用途,即as
@(…)
,数组子表达式运算符,以及as
@{…}
,一种哈希表文字,也在命令中使用。)

Splatting用于将存储在变量中的类似数组的值作为单独的位置参数传递,或者更典型地,用于将包含参数名-值对的哈希表的条目绑定到这样命名的参数-请参阅

由于变量包含字符串,并且字符串可以被视为类似数组的字符集合(通过
System.Collections.IEnumerable
接口),设置字符串变量的格式有效地将每个字符作为单独的位置参数传递

PS> $foo = 'bar'; Write-Output @foo # same as: Write-Output 'b' 'a' 'r'
b
a
r

至于你所尝试的

-Name@rgName
,基于包含字符串
'storage-dev-rg'
$rgName
,将
's'
仅第一个字符传递给
-Name
,其余字符作为单独的位置参数
't'
,第二个字符,是第一个这样的位置参数,并且由于
新AzResourceGroup
不期望任何位置参数,所以它抱怨它