Friday, 19 February 2016

Get list of inactive mailboxes in office 365 using PowerShell

User's mailboxes will be unused when they leave organization. So, you have to find all the inactive mailboxes within your organization to take further action, like removing assigned license, deleting mailbox, etc... The following powershell script generate a list of all the users who have not logged in for at least 30 days using the Exchange Online powershell cmdlet Get-StaleMailboxDetailReport. From this information you can then take the appropriate action to remove unused mailboxes.

Note: In some cases the report may not provide a LastLogin date and mailboxes under a litigation hold may also appear in this report.

#1 Open Windows PowerShell as privileged user (Run as administrator) and run the following command and type your Office 365 admin user name and password, and then click OK.
$365Logon = Get-Credential
#2 Run the following command to connect exchange online powershell session.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $365Logon -Authentication Basic -AllowRedirection
Import-PSSession $Session
#3 Finally, run the below command to get a list of users inactive for 30 days.
Get-StaleMailboxDetailReport | SELECT UserName, LastLogin, DaysInactive
You can also export the inactive mailboxes to csv file by using the powershell cmdlet Export-CSV.
Get-StaleMailboxDetailReport | SELECT UserName, LastLogin, DaysInactive|
Export-CSV "C:\\Inactive_MailBoxes_Report.csv" -NoTypeInformation -Encoding UTF8


No comments:

Post a Comment