我正在尝试搜索具有-notlike
或-notmatch
' snagit '的值的键。我可以找到与-notcontains
的完全匹配。
数据示例:
名称值HOST1 Firefox,Snagit 7,ChromeHost2 Internet,Chromehost3 snagit 5,互联网,东西
代码示例:
$global:Csv = Import-Csv -LiteralPath $global:ConvertedSNWReport
$global:hash = @{}
Import-Csv -LiteralPath $global:ConvertedSNWReport | ForEach-Object {
$global:hash[$_.'Computer name'] += @($_.Application)
}
$global:Results = $hash.GetEnumerator() | Where-Object {
$_.Value -notmatch '*Snagit*'
}
您可以嵌套Where-Object
语句来完成此操作:
$results = $hash.GetEnumerator() |Where-Object {
-not($_.Value |Where-Object {$_ -like '*snagit*'})
}
如果单个值阵列中的任何项目匹配snagit
,则表达式将评估为$false
,并且将跳过标签。相反,如果没有匹配snagit
的项目,它将评估为$true
正如Ansgar只是提醒我,评估字符串时嵌套的Where-Object
语句实际上不是必需的,因为-like
在集合上作为过滤器操作员加倍:
$results = $hash.GetEnumerator() |Where-Object {
-not($_.Value -like '*snagit*')
}