PowerShell 嵌套问题
PowerShell nesting issue
$remove = @('microsoft*','visual*')
Get-WmiObject -Class Win32_Product -ComputerName $CompName | Where-Object {
$f = $_.name -notcontains $remove
$remove | Where-Object { $f.($_) }
} | Format-Wide -Property Name -Column 1
我不确定如何正确嵌套它以便我可以过滤掉 $remove
中的所有内容并显示其余程序。我没有收到任何错误,它将等待大约 10 秒,然后继续到 PS 提示符。
notcontains 查找完全匹配项,因此不会在此处为您提供帮助。
最简单的方法可能是这样,尽管如果有很多要排除的内容,您的正则表达式可能会变得非常讨厌:
get-wmiobject -class Win32_Product -ComputerName $CompName | Where-Object {
$_.name -notmatch "^(Microsoft|Visual)."
} | Format-Wide -Property Name -Column 1
$remove = @('microsoft*','visual*')
Get-WmiObject -Class Win32_Product -ComputerName $CompName | Where-Object {
$f = $_.name -notcontains $remove
$remove | Where-Object { $f.($_) }
} | Format-Wide -Property Name -Column 1
我不确定如何正确嵌套它以便我可以过滤掉 $remove
中的所有内容并显示其余程序。我没有收到任何错误,它将等待大约 10 秒,然后继续到 PS 提示符。
notcontains 查找完全匹配项,因此不会在此处为您提供帮助。 最简单的方法可能是这样,尽管如果有很多要排除的内容,您的正则表达式可能会变得非常讨厌:
get-wmiobject -class Win32_Product -ComputerName $CompName | Where-Object {
$_.name -notmatch "^(Microsoft|Visual)."
} | Format-Wide -Property Name -Column 1