Last active
May 31, 2020 00:08
-
-
Save IISResetMe/f64c71e3b2f8ddd8cb1d3b7ea7d554c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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