This question came from an Office 365 Exchange Online administrator. The Office 365 Administration page shows they have some inactive users but it doesn't list their names.
When I log into the Office365 administrative dashboard, it shows me how many inactive users there are, but it doesn't tell me who is inactive. How can I get this information?
As you've discovered, Office 365 doesn't include the names of the inactive mailboxes, but you can use PowerShell to get a list of all users and their last login time.
Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime
If you have a large number of mailboxes, you can send the results to a CSV file and open it in Excel to sort by the date field. To output the results to a CSV file, add Export-CSV and the file path.
Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime | Export-Csv C:\Files\test.csv
Tip: If you want to save the file in the path the used in PowerShell, usually C:\Users\Username, you only need to add the folders and file name, as seen in the screenshot above, where the CSV file was saved to C:\Users\Diane\Documents.
Step-by-step instructions
- Open PowerShell using Run as Administrator. Run the following cmdlet to bring up the log in dialog. Enter the Exchange server's administrator username and password. Note, you must have administrator rights to the server to use this.
$LiveCred = Get-Credential
- Next, run this cmdlet:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
- And then run this cmdlet:
Import-PSSession $Session
- Now you're ready to get the list of users and their last logon time. If you want to output the results to a CSV file, add the Export-CSV command.
Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime | Export-Csv C:\Files\test.csv
Is there as way to get a csv list all Shared mailboxes that have not been used for a long time?
Tried it through Exchange Compliance Management but I need a hard copy of the listed mailboxes to show HoD's.
You can use PowerShell. But... if someone has the shared mailbox in their profile but are not actually using it, the last access time will be current.
Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime
This command returns list of mailboxes with display name and last logon time but I also want to get PrimarySMTPAddress of mailboxes which is part of Get-mailbox cmdlt but not a part of Get-MailboxStatistics. Anyone know ho to achive that?
So can we trust LastLogonTime? If it's null, does that really, really, REALLY mean the user has never used their account? I'm needing to clean out the unused accounts in our Office365 tenant (probably a few thousand), and I don't want to nuke accounts that may still be in use. If LastLogonTime is null, that means they've never logged-in, right? No gotchas, no exceptions?
Yeah, it would mean the user never logged in. If it is a shared mailbox, the date is the last time someone with permission to the mailbox accessed it.
Why use Excel?
Try piping to Out-GridView or just pipe to sort-object
After all we are talking PowerShell :)
Because some people might want a csv file to review later...
Hello, how can i create a report with all SMTP alliases of an account and count number of messages received on that account last 3 months? So that we can remove unused alliasses from an account.
You'll need to get all addresses on the account then search the mailbox. You can do this using VBA but i don't have a macro handy that does it. If you only need to check a few addresses, you could set up mail flow rules and either tag the subject lines (so they are easier to find) or forward to another address to monitor. But, this would only work going forward.
it is possible to change to change the UPN for another. I have the email in a csv file. im using o365
If you have the message header and it's editable, yes, but what are you trying to accomplish? There might be a better way.
for exaple change jcarlos.1234@mydomain.com to 1234@mydomain.com
This powershell will remove current addresses, replace them with the addresses in the cmdlet and set one as default.
Set-Mailbox Username -EmailAddresses SMTP:alias@domain.com,smtp:alias@domain.onmicrosoft.com,smtp:otheralias@domain.com
Need some help here.. have been tasked with finding a way to be alerted when emails reach 100 unopened emails .. any ideas ?
100 in your own inbox or across the entire exchange org?
While we can get a running total of your new mail as it arrives, counting only unread messages means we need to check the inbox every so often, just in case you read messages. It can be a little more intensive, especially if the inbox is huge as outlook needs to check each message and see if it's read.
Getting a count for all users on the server is much more difficult.
Is LastLogin a good indication of actual usage though? If staff have the mailbox attached to their Outlook install wouldn't it login every time they use Outlook and therefore not give a good enough indication of when the mailbox was actually used? Something along the lines of when the last email was received would be good??
Outlook will log in every time the mailbox is opened, so will various services. I no longer have an Exchange 2010 server running to check the results of the Get-mailbox command, but I'm pretty sure it include the last time the mailbox logged in as itself.
I don't think you'll be able to easily get a good value for 'last actively used' - a new message doesn't necessarily mean they read it. Last sent message would be better, but that also doesn't prove they didn't send a message recently. I don't have any scripts that get this information (their might be some in the TechNet gallery) and you'll need to have permission to read the mailbox.