Where -notmatch

Ask your 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.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Where -notmatch

Post by localpct »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Where -notmatch

Post by jvierra »

Another easy way to build match patterns.
  1. $apps = '.Net', 'Adobe', 'Microsoft', 'HP ', 'Intel', 'Windows SDK'
  2. #$apps = Get-Content appslist.txt
  3. $apps = $apps | ForEach-Object{ [regex]::Escape($_) }
  4. $patterns = $apps -join '|'
  5. $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.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked