I want to return all addresses with user@mydomain.org only. But there are also users that don’t have any of those and I want to return their primary SMTP address what ever it is Thank you.
Firstly, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).
The comparison operators will return TRUE or FALSE you need to use them with Where-Object to filter results.
Your situation is a bit trickier because your pseudo code is:
if (the list of proxy addresses) -notcontains '*@mycompany.org'
return the primary SMTP address
else
return all addresses that match '*@mycompany.org'
However, in PowerShell we can’t use wildcards with the contains operators.
To work around this, we can join all the addresses and check the resulting string for a match. For readability, when declaring long calculated properties, I recommend assigning the hashtable to a variable and using the variable with Select-Object:
if a users list of proxy addresses -contains '*@mydomain.org'
return ALL of those addresses ending in '*@mydomain.org' (There may be multiple, e.g. "Tom@mydomain.org" or "Tommy@mydomain.org" I would like to returrn all of those).
AND
if a user doesn't have any '*@mydomain.org' addresses return their primary SMTP address what ever it is e.g. tom@domaintwo.org
I know I am probably driving you crazy but let me try to illustrate this way. You have me so close. If a users list of proxy addresses -contains “@mydomain.org” return ALL of those addresses ending in “@mydomain.org” (There may be multiple, e.g. “Tom@mydomain.org” or “Tommy@mydomain.org” I would like to return all of those). AND if a user doesn’t have any " @mydomain.org" addresses return their primary SMTP address what ever it is e.g. tom@domaint_different.org
I am new at this and am trying to learn. I really appreciate your help and patience with my ignorance on formatting and syntax I will get there on my PowerShell journey.
All users have multiple email addresses ending in *@mydomain.org they also have other addresses with different variations and I want to return all of those addresses. e.g.
I did use Matt’s and yours code and I just can’t get them to output what I need. The problem is me not being able to explain properly what I need and my lack of PowerShell experience.
This is the best I have been able to summarize it so far:
All users have multiple email addresses ending in *@mydomain_01.org or *@mydomain_02.org. I only want to return all of the *@mydomain_01.org
Then there are users that don’t have any of those addresses ending in *@mydomain_01.org or *mydomain_02.org and I want to return their primary addresses. e.g.
You’ve explained it fine. You claim you tried Matt’s code and it returned true and that is simply incorrect. You should compare what you posted very closely to Matt’s suggestion. If his suggestion isn’t working 100%, then you should share what it did do.
You’re changing the requirements. Until now you’ve never mentioned 2 different domains yet.
Anyway the code I posted should at least provide the results for one desired domain. If you still get True instead of the desired output you’re not using the code we suggested.
Its working but it still does not include any other proxy addresses I would like. I know this is really hard to explain. Can we try a different way? How about we say return all proxy addresses except this one, and this one, and this one. That way I will get all proxy addresses and it is up to me to exclude the ones I don’t want.