You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell执行aws list-clusters如何提取无引号逗号的指定集群字符串

推荐方案(最稳定)

aws list-clusters返回结果是标准JSON格式,直接用PowerShell的JSON解析能力结构化处理即可,完全避免字符串匹配带来的多余符号问题:

$cluster = (aws list-clusters | ConvertFrom-Json).clusters | Where-Object { $_ -match 'test-staging' }

执行后$cluster的值就是纯字符串test-staging-100,没有多余的引号、逗号,且不会受返回结果排版、空格、符号位置的影响,稳定性远高于字符串匹配方案。

适配现有命令的方案

如果你要保留现有Select-String的写法,只需对匹配结果做一次字符替换,剔除引号和逗号即可:

$cluster = (aws list-clusters | Select-String "test-staging").Line -replace '["",]', ''

内容的提问来源于stack exchange,提问作者doctore

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 08:36:03