英文:
Getting error: "Missing ')' in function parameter list." while passing variable in param with hyphen in name in powershell script
问题
抱歉,你提供的脚本中存在一些问题。变量名不能包含连字符,所以你需要将变量名更改为有效的格式,然后在参数声明和脚本中使用这个有效的变量名。以下是修正后的脚本:
param($testName)
$testName = "testName-2-1-dev" # 此处更改为你的变量名
$updatePermissions = az keyvault set-policy -n $keyvault --secret-permissions get list --object-id $testName
$updatePermissions
请注意,我已将参数的名称更改为$testName
,并在脚本中将其初始化为你想要的值("testName-2-1-dev")。这样就不会再出现参数命名问题。
英文:
I have a Powershell script to which I am passing a parameters. The name of one variable has a hyphens in it (variable name format: testName-2-1-dev). But I am getting the error below while executing it:
Missing ')' in function parameter list.
Script:
param($testName-2-1-dev)
$'testName-2-1-dev' #.....2
$updatePermissions = az keyvault set-policy -n $keyvault --secret-permissions get list --object-id $testName`-2`-1`-dev
$updatePermissions
I tried to add quotes same as that in 2 and also tried to add ` character before the hyphen, but it did not work out. Can I please get help in this?
答案1
得分: 2
你需要使用花括号 (${...}
) 来限定参数/变量名:
param(${testName-2-1-dev})
az keyvault set-policy -n $keyvault --secret-permissions get list --object-id ${testName-2-1-dev}
现在你可以这样调用它:
.\script.ps1 -testName-2-1-dev 123
英文:
You need to use curly brackets (${...}
) to qualify the parameter/variable name:
param(${testName-2-1-dev})
az keyvault set-policy -n $keyvault --secret-permissions get list --object-id ${testName-2-1-dev}
Now you can invoke it with:
.\script.ps1 -testName-2-1-dev 123
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论