gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:07:47 24 4
gpt4 key购买 nike

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

(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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com