Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active May 31, 2020 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/f64c71e3b2f8ddd8cb1d3b7ea7d554c2 to your computer and use it in GitHub Desktop.
Save IISResetMe/f64c71e3b2f8ddd8cb1d3b7ea7d554c2 to your computer and use it in GitHub Desktop.
function NotMatchAny {
param(
[Parameter(Mandatory)]
[string[]]$Excludes,
[string]$Property,
[switch]$First,
[switch]$Last
)
$WordList = $Excludes.ForEach({[regex]::Escape($_)}) -join '|'
$Pattern = '(?:{0})' -f $WordList
if($First){
$Pattern = '^{0}' -f $Pattern
}
if($Last){
$Pattern = '{0}$' -f $Pattern
}
return $(if($Property){
{ $_.$Property -notmatch $Pattern }
} else {
{ $_ -notmatch $Pattern }
}).GetNewClosure()
}
$Excludes = 'atl','na','mdm','aus','okc','ssc','ga1','ok1','fns','acs'
$Words = 'mdm','opw','erp','atl','ssa'
$Words | ? (NotMatchAny $Excludes -First)
$Objects = $Words.ForEach({New-Object psobject -Property @{P=$_}})
$Objects | ? (NotMatchAny $Excludes P -First)
function NotMatchAny {
param([string[]]$Excludes)
return { $_ -notmatch "($($Excludes.ForEach({[regex]::Escape($_)}) -join '|'))" }.GetNewClosure()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment