I’ve been trying to write a PS script to do a search for matching proxy addresses and I’m running into trouble. The script has 2 criteria for matching:
Criteria 1 - Filter out users who have a primary e-mail address that matches a given value (“@contoso.com”, for instance).
Criteria 2 - For the remaining user list, use the primary e-mail address prefix (the part of the e-mail address that goes before the “@”) and see if that string exists in any of the user’s proxy addresses. If it does, don’t do anything. If there is no match, write out user info to a .csv file.
I’ve got criteria 1 working. The problem is with criteria 2. The list of proxy addresses is a string object type, but no matter what comparison operator I use, the output of the script is the entire list of filtered users, even those where the email prefix exists in the proxy address list. Here’s the code snippet:
$proxyaddresses is a System.String object type that contains a list of e-mail addresses found in the user’s proxyaddress list. If I list the contents of the variable on the screen, I get: SMTP:john.doe@contoso.com SMTP:jdoe@acme.com
x.400:c=US;a= p=contoso;O=Exchange;s=doe,g=john
the only consistent delimiter would probably be a space.
Would work, because Contains() is a legit operation. The problem is that $mailprefix isn’t EXACTLY matching, because what’s in $proxyaddress also has SMTP: and the domain name in it. Contains() doesn’t do a wildcard match, it searches for one object within another. It’s the same as the -Contains operator and -eq or -like; see https://devopscollective.gitbooks.io/the-big-book-of-powershell-gotchas/content/manuscript/contains-isnt-like.html. I’ll also note that you weren’t telling Out-File to output anything ;).
We probably need to enumerate the proxy addresses.
Thanks, Don - I need to evaluate the proxyaddresses as a whole, not each individual one. The idea is that info gets written to a .csv file ONLY if the $mailprefix value is not present in ANY of the proxy addresses for the user. If it is, don’t do anything at all. That’s why I was hoping that the $proxyaddresses variable was a regular string object, so I could just do a substring match into 1 object instead of 3 or 4.
By combining the addresses into a pipe-delimited string, we can run -like against the entire set. But, $proxyaddresses remains a collection, so when piped to Out-File you’ll still get one per line.
Sorry for the delay. Out of the office for a while.
The comparison function doesn’t appear to be working. It writes user info to the .csv file even when there’s a match between the $combo & the $mailprefix value.