locked
parsing SMTP: string RRS feed

  • Question

  • I have a string

    $str="smtp:asif@hotmail.com SMPT:Asif.A@hotmail.com smtp:asif.AAA@hotmail.com"

    i want to pull only the email starting with SMTP:

    please help me

    Tuesday, February 25, 2020 3:13 PM

Answers

  • SMTP addresses aren't as simple to deal with as they seem in your example.

    For example, it's possible (although it's no longer used very often) to have a space (or other "special character") in the "local-part" of the address that requires quoting (e.g., "Full Name"@domain.edu).

    Is your string using space or tab characters to separate the addresses?

    Are these addresses coming from a MS Exchange object in the AD? If so, why not use the property "PrimarySMTPAddress" from the mail/mailbox-enabled user/contact/group/etc.? That makes things a lot easier.

    If you're dealing with AD objects and their proxy addresses, you can follow this article:

    https://itfordummies.net/2015/06/17/identify-primary-smtp-address-from-active-directory-with-powershell/


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by asif300 Thursday, February 27, 2020 4:51 PM
    Tuesday, February 25, 2020 7:55 PM

All replies

  • Use a case sensitive regex.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, February 25, 2020 3:35 PM
  • SMTP addresses aren't as simple to deal with as they seem in your example.

    For example, it's possible (although it's no longer used very often) to have a space (or other "special character") in the "local-part" of the address that requires quoting (e.g., "Full Name"@domain.edu).

    Is your string using space or tab characters to separate the addresses?

    Are these addresses coming from a MS Exchange object in the AD? If so, why not use the property "PrimarySMTPAddress" from the mail/mailbox-enabled user/contact/group/etc.? That makes things a lot easier.

    If you're dealing with AD objects and their proxy addresses, you can follow this article:

    https://itfordummies.net/2015/06/17/identify-primary-smtp-address-from-active-directory-with-powershell/


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by asif300 Thursday, February 27, 2020 4:51 PM
    Tuesday, February 25, 2020 7:55 PM