[英]Getting TSV file output excluding 2 resource types from the az resource list in Azure CLI
我需要从 azure CLI 中获取 azure 资源列表,不包括 2 种资源类型和 output 文件到 TSV 文件。 我能够通过以下命令通过 PowerShell 执行此操作。
PowerShell 命令
get-azresource | where ResourceType -notmatch microsoft.network/privatednszones/virtualnetworklinks | where ResourceType -notmatch microsoft.insights/actiongroups | export-csv C:\Users\7.csv
我需要从 Azure CLI 中获取此结果,将提到的资源类型排除到 TSV 文件中(因为我们无法在 CSV 中获取 Azure CLI output)
您需要查找Export-Csv的信息,您可以在其中看到它有一个参数-Delimiter
用于将不同的字符设置为字段分隔符(在您的情况下为 TAB 字符)而不是默认的逗号。
为了防止在带有字段类型定义的 output 文件顶部多出一行,还有一个开关-NoTypeInformation
然后查看您的代码我有一些评论:
-notmatch
这是一个正则表达式比较运算符,但要比较的字符串具有在正则表达式中具有特殊含义的字符(最显着的是点)尝试
# the resource types to exclude
$exclude = 'microsoft.network/privatednszones/virtualnetworklinks', 'microsoft.insights/actiongroups'
# create a regex string from the $exclude array, where the elements are joined with the regex OR ('|')
$notThese = ($exclude | ForEach-Object { [regex]::Escape($_) }) -join '|'
Get-AzResource | Where-Object {$_.ResourceType -notmatch $notThese} |
Export-Csv -Path 'C:\Users\7.tsv' -Delimiter "`t" -NoTypeInformation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.