question

Learner27-5378 avatar image
0 Votes"
Learner27-5378 asked joyceshen-MSFT commented

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

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???

windows-server-powershelloffice-exchange-server-administrationoffice-exchange-server-mailflow
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Learner27-5378

Any progress about your issue? Share your update here if any

0 Votes 0 ·
joyceshen-MSFT avatar image
0 Votes"
joyceshen-MSFT answered

Hi @Learner27-5378

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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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).

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ManuPhilip avatar image
0 Votes"
ManuPhilip answered RichMatheisen-8856 commented

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

  1. 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


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

A "contact" is not a security principal and cannot log in.

0 Votes 0 ·