I'm attempting to search a hash table for keys that have values that are -notlike or -notmatch 'Snagit'. I am able find an exact match with -notcontains.
Data Example:
Name Value Host1 FireFox,Snagit 7,Chrome Host2 Internet,Chrome Host3 Snagit 5,Internet,Stuff
Code Example:
$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*'
}
Host2entry, is that correctly understood?*Snagit*is not a valid regular expression (-match,-notmatch). It's a pattern for wildcard matches (-like,-notlike). For a regular expression you don't need to match leading or trailing text, since they aren't anchored by default (you need^and/or$for anchoring them), whereas wildcard patterns are by default anchored at beginning and end of a string.