Is there a way to find in use and not in use Mail contacts in MS Exchange O365?

Learner_27 1 Reputation point
2021-07-19T04:54:45.23+00:00

We have requirement to fetch report of active or in use/not in use Mail contacts & Mail users from Exchange admin center and if can get report for last 6 or 3 months active contacts as we need to perform some contact cleanup activity. Is there a way to get it from PowerShell commands/ Exchange reporting....?

Already checked for Get-MessageTrace. So, if there can be an alternative to get active mail contacts details and any PowerShell script available???

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,369 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Manu Philip 16,991 Reputation points MVP
    2021-07-19T05:32:04.823+00:00

    I have prepared two PS scripts for you to get last logged in details, one for to get mailusers details and other for mailcontacts details. The csv results can help to decide on your cleanup
    First of all connect to the Office 365 tenant

    $LiveCred = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
    Import-PSSession $Session
    

    Run the script one by one (eg: .\mailuser.ps1). Make sure that you have a folder created as temp under C:\

    1. Mail Contacts $Result=@() $mailboxes = Get-MailContact -ResultSize Unlimited $totalmbx = $mailboxes.Count $i = 1 $mailboxes | ForEach-Object { $i++ $mbx = $_ $mbs = Get-MailContact -Identity $mbx.UserPrincipalName | Select LastLogonTime if ($mbs.LastLogonTime -eq $null){ $lt = "Never Logged In" }else{ $lt = $mbs.LastLogonTime } $Result += New-Object PSObject -property @{ Name = $mbx.DisplayName UserPrincipalName = $mbx.UserPrincipalName LastLogonTime = $lt } } $Result | Export-CSV "C:\temp\LastLogon-details-contacts.csv" -NoTypeInformation -Encoding UTF8
    2. Mail Users $Result=@()
      $mailboxes = Get-MailUser -ResultSize Unlimited
      $totalmbx = $mailboxes.Count
      $i = 1
      $mailboxes | ForEach-Object {
      $i++
      $mbx = $_
      $mbs = Get-MailUser -Identity $mbx.UserPrincipalName | Select LastLogonTime
      if ($mbs.LastLogonTime -eq $null){
      $lt = "Never Logged In"
      }else{
      $lt = $mbs.LastLogonTime }
      $Result += New-Object PSObject -property @{
      Name = $mbx.DisplayName
      UserPrincipalName = $mbx.UserPrincipalName
      LastLogonTime = $lt }
      }
      $Result | Export-CSV "C:\temp\LastLogon-details.csv" -NoTypeInformation -Encoding UTF8

    Results are expected to be saved under C:\temp


  2. Rich Matheisen 45,096 Reputation points
    2021-07-19T15:02:44.37+00:00

    If your definition of "in-use" is the sending or receiving of e-mail, I think the only way to do this is to use log files (either SMTP or message tracking).

    0 comments No comments

  3. Joyce Shen - MSFT 16,646 Reputation points
    2021-07-20T02:43:44.08+00:00

    Hi @Learner_27

    I agree with the suggestion above, we may consider checking the time of the mails send to the contacts. Like this similar thread discussed: Inactive Contacts

    A powershell script to get the email address of each contact, then search the mailbox for any items where that email address is the To, Cc, Bcc or From address, then dump the creation date of that item to a csv.

    In addition, please note that our forum is for questions and feedback related to Exchange server. Usually, we also help users modify their scripts when they have an issue with it, but we don't support for writing scripts directly. If you have a need for scripts, you could modify/add a tag "office-exchange-server-dev"

    And for more information about mail user and mail contacts in Exchange online: Manage mail users in Exchange Online


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments