简体   繁体   English

Azure Cli PowerShell - 如何将列表查询结果(数组)作为内联参数传递?

[英]Azure Cli PowerShell - how to pass list query results (array) as inline Parameters?

In Azure Cli with Powershell. What I'm trying to do is list out all the existing KV secret names and then pass the array in as an inline parameter for ' az deployment group create ' command.在带有 Powershell 的 Azure CLI 中。我要做的是列出所有现有的 KV 机密名称,然后将数组作为内联参数传递给“ az deployment group create ”命令。 在此处输入图像描述

However, seems like the command doesn't like the format of JSON array so I got this error: ERROR: Failed to parse string as JSON但是,似乎该命令不喜欢 JSON 数组的格式,所以我收到此错误:错误:无法将字符串解析为 JSON

Upon checking docus, seems like it want something like "['value1','value2']" but my query result is ["t1","t2"] , so it will throw the error out.在检查文档时,它似乎想要类似"['value1','value2']" 的东西,但我的查询结果是["t1","t2"] ,所以它会抛出错误。 在此处输入图像描述

This surprised me as the query result are not supported natively by Azure CLI, wondering how can I convert my query results to the right format?这让我感到惊讶,因为 Azure CLI 本身不支持查询结果,想知道如何将查询结果转换为正确的格式?

 $formattedOutput = @() foreach($line in $secretNamesArray) { $formattedOutput += "'"+$line+"'" } $existingSecretNames = "[" + ($formattedOutput -join ",") + "]"

Figured out, have to transform it.... what a wonderful job MS...弄清楚了,必须对其进行改造....多么出色的MS ......

also remember to wrap the results with double quote as well like:还记得用双引号将结果括起来,比如:

--parameters existingSecretNames="$existingSecretNames"

So it will pass something in like "['t1', 't2', 't3']"所以它会传递类似“['t1','t2','t3']”的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell Az 在接受数组参数的计划中创建 Azure 策略 - Powershell Az to create Azure Policy in an Initiative That Accepts An Array Parameters AWS CLI - 列出未加密的卷并筛选结果 --query - AWS CLI - List Unencrypted Volumes and Filter Results --query 如何在 PowerShell 内向 Azure CLI 提供 SAS 令牌 - How to provide a SAS token to Azure CLI within PowerShell 如何 SQL 在 MS Azure CosmosDB 中查询嵌套列表和数组? - How to SQL query a nested list and array in a MS Azure CosmosDB? 在 Azure Powershell 任务中使用 Azure CLI - Use Azure CLI within Azure Powershell Task Azure CLI 和 SAS Token issue in PowerShell - Azure CLI and SAS Token issue in PowerShell 如何从 Azure PowerShell/ Azure CLI 中提取连接字符串和文件服务 SAS URL? - How to extract Connection String and File Service SAS URL from Azure PowerShell/ Azure CLI? Gitlab azure cli多行参数 - Gitlab azure cli multiple lines parameters 如何将启用 MFA 的 Azure 帐户凭据传递到 PowerShell ScriptBlock? - How to pass MFA enabled Azure account credentials into PowerShell ScriptBlock? 如何将参数从 azure 管道传递到 shell 脚本? - How to pass parameters from azure pipeline to shell script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM