Link to home
Start Free TrialLog in
Avatar of Techrunner

asked on

Mailboxes Not Accessed for certain time

Hello Experts,
I have exchange 2010 SP2
I am looking for a way to get a report that list the mailboxes based on distribution group that have not been accessed in 15 day or 30 days and export them into excel format.

Please any help

Avatar of Haresh Nikumbh
Haresh Nikumbh
Flag of India image

Mailboxes that have never been logged on to:

Get-MailboxStatistics -resultsize unlimited | where {$_.LastLogonTime -eq $null | ft displayName,lastlogontime,lastloggedonuseraccount,servername

List of mailboxes that haven’t been accessed in the last X days. Let’s use 7 days as the value here:

Get-MailboxStatistics -resultsize unlimited | where {$_.LastLogonTime -lt (get-date).AddDays(-7)} | ft displayName,lastlogontime,lastloggedonuseraccount,servername

Source :
If you are going to filter the users based on DG membership, try something like this:

# group name goes here, or obtain it from user prompt
$members = Get-DistributionGroupMember -Identity "sec grp"

$arrResult = @()

# modify the end date here
$date = (get-date).AddDays(-15)

foreach ($m in $members) {
	$objProperties = New-Object PSObject
	$temp = Get-MailboxStatistics -Identity $m.SamAccountName

# skip users that have never logged in
	if (!$temp.LastLogonTime) { continue; }

	if ($temp.LastLogonTime -lt $date) {

# Add another properties to export as necessary

		Add-Member -InputObject $objProperties -MemberType NoteProperty -Name "DisplayName" -Value $m.DisplayName
		Add-Member -InputObject $objProperties -MemberType NoteProperty -Name "SamAccountName" -Value 

		Add-Member -InputObject $objProperties -MemberType NoteProperty -Name "PrimarySmtpAddress" -Value 

		Add-Member -InputObject $objProperties -MemberType NoteProperty -Name "LastLogonTime" -Value 


		$arrResult += $objProperties

# modify export path here
$arrResult | Export-Csv -Path ".\test.csv" -NoTypeInformation

Open in new window

Avatar of Techrunner


Thanks for the reply. Is there any to get status based on groups.

get-mailboxstatistics -server am-lon-ex02 | where {($_.LastLogonTime -lt (get-date).adddays(-30)) -and ($_.ObjectClass -eq "Mailbox")} | out-file mailboxes.txt
Currently I am using Promodag reports to generate exchange reports I am not this will fulfill my requirement

The above script is batch file or vb script ??

mine is exchange powershell
How I can run the above command with exchange shell. Just copy and paste the above script ??
yes  just replace this
your exchange server name
Do you I have to completely copy the script ( replacing server name ) and paste it to exchange powershell.

I ran the commands but it ended as shown and not file was createdUser generated image
Please any advise.
Avatar of Techrunner

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the experts help.
I solved it myself using Promodag Reporting Tool.