Where -notmatch

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 248
Joined: Wed Sep 09, 2015 12:53 pm

Re: Where -notmatch

Post by localpct » Fri May 19, 2017 11:17 am

Are there any advantages against
$_.Name -notmatch ($textbox1.Text + '|\.dpx|\.LOG2|\.Net Data|vendor|install|etc.. ')

or those two you just proposed?

I've ran this against 50 machines today and only one failed because it has an exact match of
Adobe Acrobat 11
Adobe Acrobat 11 vendor

I'm not too concerned about it since Adobe Acrobat 11 is not our standard and everyone should be on the latest DC

User avatar
Posts: 12157
Joined: Tue May 22, 2007 9:57 am

Re: Where -notmatch

Post by jvierra » Fri May 19, 2017 11:37 am

Another easy way to build match patterns.
  1. $apps = '.Net', 'Adobe', 'Microsoft', 'HP ', 'Intel', 'Windows SDK'
  3. #$apps = Get-Content appslist.txt
  5. $apps = $apps | ForEach-Object{ [regex]::Escape($_) }
  7. $patterns = $apps -join '|'
  9. $nametomatch -match $pattern
This escaped all strings and combines into a match pattern. It is up to you to decide how to specify the match.