Powershell 中的 JQ 查询不适用于 SELECT 中的变量

JQ query in powershell is not working with variable in SELECT

In Power shell 我正在尝试 运行 Oracle Cloud CLI 命令并使用 JQ 对其进行过滤。 如果我在 JQ select 中使用硬编码值,它工作正常..但是如果我使用变量,我不会得到任何数据。请帮忙。

使用 select 中的硬编码值:

oci compute instance list-vnics --all --compartment-id xxxxx  --profile myprof |C:\myfiles\jq-win64.exe '.data[]|select(.\"hostname-label\"==\"test1\")'

Select 中的变量代码失败:

oci compute instance list-vnics --all --compartment-id xxxxx  --profile myprof |C:\myfiles\jq-win64.exe '.data[]|select(.\"hostname-label\"==\"$host_name\")'

PowerShell 不会扩展单引号字符串中的变量。

$ociResult = oci compute instance list-vnics --all --compartment-id xxxxx --profile myprof
$jqExpr = '.data[]|select(.\"hostname-label\"==\"' + $host_name + '\")'

$ociResult | C:\myfiles\jq-win64.exe $jqExpr