Where -notmatch

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
User avatar
Posts: 221
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: 11258
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.

Code: Select all

$apps = '.Net', 'Adobe', 'Microsoft', 'HP ', 'Intel', 'Windows SDK'
#$apps = Get-Content appslist.txt
$apps = $apps | ForEach-Object{ [regex]::Escape($_) }
$patterns = $apps -join '|'
$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.