中使用PowerShell"其中"命令来比较值的数组 [英] Using Powershell "where" command to compare against Array of values
问题描述
我试图找出一种方式来获得该命令从值的数组来过滤,而不是一个值。目前,这是我的code是如何(和它的作品当$ ExcludeVerA是一个值):
I'm trying to figure out a way to get this command to filter from an array of values as opposed to one value. Currently this is how my code is (and it works when $ExcludeVerA is one value):
$ExcludeVerA = "7"
$java = Get-WmiObject -Class win32_product | where { $_.Name -like "*Java*"} |
where ({ $_.Version -notlike "$ExcludeVerA*" })
和我想$ ExcludeVerA有像这样值的数组(这个目前不工作):
And I'd like $ExcludeVerA to have an array of values like so (this currently doesn't work):
$ExcludeVerA = "7", "3", "4"
foreach ($x in $ExcludeVerA)
{
$java = Get-WmiObject -Class win32_product | where { $_.Name -like "*Java*"} |
where ({ $_.Version -notlike "$ExcludeVerA*" })
}
什么我可以做的,为什么code的第二块不起作用任何意见或其他的想法?
Any ideas of why this second block of code doesn't work or other ideas of what I can do?
推荐答案
尝试 -notcontains
where ({ $ExcludeVerA -notcontains $_.Version })
所以,如果我的理解corretly,然后
so if I understand it corretly, then
$ExcludeVerA = "7", "3", "4"
$java = Get-WmiObject -Class win32_product | where { $_.Name -like "*Java*"} |
where ({ $ExcludeVerA -notcontains $_.Version })
这是直接回答你的问题。可能的解决办法是这样的:
That was direct answer to your question. Possible solution might be something like this:
$ExcludeVerA = "^(7|3|4)\."
$java = Get-WmiObject -Class win32_product |
where { $_.Name -like "*Java*"} |
where { $_.Version -notmatch $ExcludeVerA}
使用它来获得完成工作正则表达式。
it uses regex to get job done.
这篇关于中使用PowerShell"其中"命令来比较值的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!