none
script for listing email addresses from two domains

    Question

  • Greetings!

    Does anyone know a powershell script which would list email addresses from users in primary and secondary domain?

    with best regards,


    bostjanc

    Wednesday, March 07, 2012 2:06 PM

Answers

  • I have solved it with this script:

    foreach($mailaddress in Get-Recipient -domaincontroller domain.company.local -Resultsize unlimited | select -expand Emailaddresses | %{$_.SmtpAddress} | sort)
    {
    if ($mailaddress -like '*@domain.com')
    {
    $mailaddress+' OK'
    }
    }
    foreach($mailaddress in Get-Recipient -domaincontroller domain2.company2.local -Resultsize unlimited | select -expand Emailaddresses | %{$_.SmtpAddress} | sort)
    {
    if (($mailaddress -like '*@company.com')  -or ($mailaddress -like '*@company.si'))
    {
    $mailaddress+' OK'
    }
    }


    bostjanc

    Thursday, March 08, 2012 8:38 AM

All replies

  • Do you mean to email domains in the same active directory domain? There is a property called emailaddresses. This is an array that will show all email addresses associated with that user account. Is that what you want?
    Wednesday, March 07, 2012 8:53 PM
  • I have solved it with this script:

    foreach($mailaddress in Get-Recipient -domaincontroller domain.company.local -Resultsize unlimited | select -expand Emailaddresses | %{$_.SmtpAddress} | sort)
    {
    if ($mailaddress -like '*@domain.com')
    {
    $mailaddress+' OK'
    }
    }
    foreach($mailaddress in Get-Recipient -domaincontroller domain2.company2.local -Resultsize unlimited | select -expand Emailaddresses | %{$_.SmtpAddress} | sort)
    {
    if (($mailaddress -like '*@company.com')  -or ($mailaddress -like '*@company.si'))
    {
    $mailaddress+' OK'
    }
    }


    bostjanc

    Thursday, March 08, 2012 8:38 AM
  • Hi,

    Glad that you solved it. And thanks for your sharing of the method.

    Best Regards,

    Yan Li


    Yan Li

    TechNet Community Support

    Thursday, March 08, 2012 8:40 AM
    Moderator