I have array of strings
$Emails = '[email protected]','[email protected]','[email protected]' This array can contain from 1 to unlimited numbers of elements.
And I need to build a filter string from this array like that:
"(PrimarySmtpAddress -ne '[email protected]') -and (PrimarySmtpAddress -ne '[email protected]') -and (PrimarySmtpAddress -ne '[email protected]')" This is the only direct approach I could come up with:
$out = $null foreach ($i in $ExcludedEmails) { if ($out -eq $null) { $out = "(PrimarySmtpAddress -ne '$i')" } else { $out += " -and (PrimarySmtpAddress -ne '$i')" } } This code produces the expected result. But I'd like to know if there's a more elegant solution using some built-in function of the String class or something like that.
Is there any?