Hallo everybody,
i have an issue with my Admin-Tool. For your information: the script was already running on my system but after few weeks i get some problems.
I start a session with our Exchange-Server and collect from there some information about the user. Now i want to get all Smtp adresses, split in primary- and normal emailaddresses. If i start the snippet below i get only the primaryemailaddress. If i start the snippet localy on the server i get both informations.
The snippet is: Get-Mailbox -Identity $selectedUser.SamAccountName -ResultSize Unlimited | Select-Object PrimarySmtpAddress, @{ Name = "EmailAddresses"; Expression = { $_.EmailAddresses | Where-Object { $_.PrefixString -ceq "smtp" } | ForEach-Object { $_.SmtpAddress } } }
Can someone help me there? I dont know why the server didnt return me both informations. Or is there a better way to get the smtpaddresses?
SMTP-Addresses Exchange
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: SMTP-Addresses Exchange
I think the following would work better:
Get-Mailbox $selectedUser.SamAccountName |
Select-Object PrimarySmtpAddress, @{n='EmailAddresses';e={ $_.EmailAddresses -join '|'}}
Get-Mailbox $selectedUser.SamAccountName |
Select-Object PrimarySmtpAddress, @{n='EmailAddresses';e={ $_.EmailAddresses -join '|'}}
Re: SMTP-Addresses Exchange
That sounds very good. Now i get all information like x500, MRS and SMTP.
Can you tell me how i can filter only the SMTP-Address?
Can you tell me how i can filter only the SMTP-Address?
Re: SMTP-Addresses Exchange
Code: Select all
$select = @(
'PrimarySmtpAddress',
@{n='EmailAddresses';e={$_.EmailAddresses.Where({$_ -match 'smtp:' }) -join '|'}}
)
Get-Mailbox $selectedUser.SamAccountName | select $select
Re: SMTP-Addresses Exchange
I thank you very much.
Just some little modifies on my code:
Just some little modifies on my code:
Code: Select all
Get-Mailbox $selectedUser.SamAccountName | select PrimarySmtpAddress, @{Name='EmailAddresses'; Expression={$_.EmailAddresses.Where({$_ -like 'smtp:*' }) -replace "smtp:",""}}
- ITEngineer
- Posts: 216
- Last visit: Thu Mar 23, 2023 5:45 pm
- Has voted: 4 times
Re: SMTP-Addresses Exchange
Thanks for posting such great script
So is it possible to put comma "," in the EmailAddresses column result?
EmailAddresses
Email1@domain.com, Email2@domain.com, Email3@domain.com, ...
So is it possible to put comma "," in the EmailAddresses column result?
EmailAddresses
Email1@domain.com, Email2@domain.com, Email3@domain.com, ...
/* IT Engineer */
Re: SMTP-Addresses Exchange
Yes it's possible.
But i dont know which code you use...
If you use my last posted code you will recive the EmailAddresses with "," separated instand of "|"
Use this:
But i dont know which code you use...
If you use my last posted code you will recive the EmailAddresses with "," separated instand of "|"
Use this:
Code: Select all
Get-Mailbox $selectedUser.SamAccountName | select PrimarySmtpAddress, @{Name='EmailAddresses'; Expression={$_.EmailAddresses.Where({$_ -like 'smtp:*' }) -replace "smtp:",""}}
- ITEngineer
- Posts: 216
- Last visit: Thu Mar 23, 2023 5:45 pm
- Has voted: 4 times
Re: SMTP-Addresses Exchange
Yes, I've used the above code.bhnuser wrote: ↑Thu Jul 26, 2018 5:53 am Yes it's possible.
But i dont know which code you use...
If you use my last posted code you will recive the EmailAddresses with "," separated instand of "|"
Use this:Code: Select all
Get-Mailbox $selectedUser.SamAccountName | select PrimarySmtpAddress, @{Name='EmailAddresses'; Expression={$_.EmailAddresses.Where({$_ -like 'smtp:*' }) -replace "smtp:",""}}
When I open the result.CSV it is showing with blank space as the delimiter not comma.
/* IT Engineer */
Re: SMTP-Addresses Exchange
I had it set up correctly but the OP decided to make odd changes that make it behave badly.
Here. This makes it a comma.
Here. This makes it a comma.
Code: Select all
$select = @(
'PrimarySmtpAddress',
@{n='EmailAddresses';e={$_.EmailAddresses.Where({$_ -match 'smtp:' }) -join ','}}
)
Get-Mailbox $selectedUser.SamAccountName | select $select
Re: SMTP-Addresses Exchange
To easily strip the "smtp:" just add this:
Notice that "replace" does not require an empty string to remove the matched value.
Code: Select all
$select = @(
'PrimarySmtpAddress',
@{n='EmailAddresses';e={$_.EmailAddresses.Where({$_ -match 'smtp:' } -replace 'smtp:' -join ','}}
)
Get-Mailbox | select $select