azure - 针对 "-or"Powershell 情况的更好方法

标签 azure powershell resources

我有这段代码,真相看起来很纠结,我想让它看起来更漂亮

(Get-AzResource | 其中 {($_.tags.tag1-eq $null) - 或 ($_.tags.tag2-eq $null) - 或 ($_.tags.tag3-eq $null) - 或 ($_.tags.tag4-eq $null) - 或 ($_.tags.tag5-eq "") - 或 ($_.tags.tag6-eq "") - 或 ($_ .tags.tag7-eq "")}

这段代码实现了查找没有某些标签且为空的资源的功能,但问题是我留下了一个“-or”,我可以通过某种方式让它变得更漂亮吗?

最佳答案

使用-contains operator :

Get-AzResource | Where-Object {
  ($_.tags.tag1, $_.tags.tag2, $_.tags.tag3, $_.tags.tag4 -contains $null) -or
  ($_.tags.tag5, $_.tags.tag6, $_.tags.tag7 -contains '')
}

注意:考虑到相对的 operator precedence-contains 操作周围的 (...) 并不是绝对必要的。 -contains-or

关于azure - 针对 "-or"Powershell 情况的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74379668/

相关文章:

javascript - 如何在 javascript 文件中使用 ASP.NET Resource(.resx) 字符串

azure - Windows Azure 上单个 VM 内的 Window Server 2012 和 SQL Server 2012

Azure:不要通过配置部署角色

PowerShell - 如何使用另一个变量调用变量?

android - 在 Eclipse 中删除文件导致每个图像都是错误的

css - 如何在 Hippo CMS 中包含 CSS 文件?

azure - 无法连接两个 Azure 虚拟机 - 权限被拒绝(公钥)

azure - 如何获取 azure 机器人密码

powershell - 使用 Powershell 转换 XML - 这个 Sed 命令的等价物是什么?

powershell - Databricks API 2.0 - 使用服务主体凭据在 powershell 中创建 secret 范围