Exchange Server 2013 ActiveSync User Report Script


This script works in co-existence mode of Legacy Version of Exchange Server with Exchange Server 2013 and is used to fetch the user information from Exchange 2007 and 2013. It provides the detail in html format. The Output will have complete detail of user information like DisplayName, EmailAddress, ServerName, DatabaseName, MailboxSize, ItemCount, ActiveSyncMailboxPolicy, DeviceType, LastSyncAttemptTime, LastSuccessSync. It should be executed on the respective Exchange mangement shell to get user details. For Example:Exchange 2007 User report will work only in Exchange Server 2007 Management Shell and Exchange 2013 user report will only in Exchange 2013 Management Shell. The reason is by default few Exchange Powershell command doesn’t have forward and backward compatibility.

The script is written with easy logic where you can able to customize based upon your requirement

########################################################################################

The below report is used to fetch the user information from Exchange 2007 and 2013. It provides the detail in html format.
The Output will have complete detail of user information like DisplayName, EmailAddress, ServerName, DatabaseName, MailboxSize, ItemCount, ActiveSyncMailboxPolicy, DeviceType, LastSyncAttemptTime, LastSuccessSync. It should be executed on the respective Exchange mangement shell to get user details. Exchange 2007 User report will work only in Exchange Server 2007 Management Shell and Exchange 2013 user report will only in Exchange 2013 Management Shell. The reason is by default few Exchange Powershell command doesn’t have forward and backward compatibility.

########################################################################################

Write-host “Exchange Server Users List Report
———————————
1. Need to Prepare Exchange Server 2007 User List Report
2. Need to Prepare Exchange Server 2013 User List Report” -ForeGround “Cyan”

Write-Host ” ”
$number = Read-Host “Choose The Task”
$output = @()
switch ($number)
{

1 {

## Exchange Server 2007 User List Report
## HTML PAGE FORMAT

$a = “<style>”
$a = $a + “BODY{background-color:Lavender;}”
$a = $a + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
$a = $a + “TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Bisque}”
$a = $a + “TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Beige}”
$a = $a + “</style>”

## HTML PAGE FORMAT

# Collecting Exchange Server Version

$MailboxServer = Get-Exchangeserver | Where {$_.AdminDisplayVersion -like “Version 8*” -and $_.ServerRole -like “Mailbox*”}

ForEach ($server in $MailboxServer)

{

# Collecting user list for the Exchange Server

$UserList = Get-ExchangeServer -Identity $Server | Get-Mailbox -ResultSize Unlimited

#Creating Array to collect each user information

$report = @()

foreach ($User in $UserList)

{

$CASInfo = Get-CasMailbox -identity $user
$MBXInfo = Get-Mailbox -Identity $user
$MBXStat = Get-MailboxStatistics -Identity $user
$ASStat = Get-ActiveSyncDeviceStatistics -Mailbox $user

$mbObj = New-Object PSObject
$mbObj | Add-Member -MemberType NoteProperty -Name “DisplayName” -Value $MBXInfo.DisplayName
$mbObj | Add-Member -MemberType NoteProperty -Name “EmailAddress” -Value $MBXInfo.PrimarySmtpAddress
$mbObj | Add-Member -MemberType NoteProperty -Name “ServerName” -Value $MBXStat.ServerName
$mbObj | Add-Member -MemberType NoteProperty -Name “DatabaseName” -Value $MBXStat.DatabaseName
$mbObj | Add-Member -MemberType NoteProperty -Name “MailboxSize” -Value $MBXStat.TotalItemSize
$mbObj | Add-Member -MemberType NoteProperty -Name “ItemCount” -Value $MBXStat.ItemCount
$mbObj | Add-Member -MemberType NoteProperty -Name “ActiveSyncMailboxPolicy” -Value $CASInfo.ActiveSyncMailboxPolicy
$mbObj | Add-Member -MemberType NoteProperty -Name “DeviceType” -Value $ASStat.DeviceType
$mbObj | Add-Member -MemberType NoteProperty -Name “LastSyncAttemptTime” -Value $ASStat.LastSyncAttemptTime
$mbObj | Add-Member -MemberType NoteProperty -Name “LastSuccessSync” -Value $ASStat.LastSuccessSync
$report += $mbObj

}

$rreport += $report

}

# Preparation of User List Report in HTML Format

$rreport | Sort-Object “LastSuccessSync” -descending | Select-Object DisplayName, EmailAddress, ServerName, DatabaseName, MailboxSize, ItemCount, ActiveSyncMailboxPolicy, DeviceType, LastSyncAttemptTime, LastSuccessSync | ConvertTo-Html -body “<h2> Users List Report – Exchange Server 2007</h2>” -head $a | Set-Content c:\temp\Exchange2007UserReport.html

Invoke-Expression C:\temp\Exchange2007UserReport.html }

2 {

## Exchange Server 2013 User List Report

## HTML PAGE FORMAT 

$a = “<style>”
$a = $a + “BODY{background-color:Lavender;}”
$a = $a + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
$a = $a + “TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Bisque}”
$a = $a + “TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Beige}”
$a = $a + “</style>”

## HTML PAGE FORMAT

## Collecting Exchange Server Version

$MailboxServer = Get-Exchangeserver | Where {$_.AdminDisplayVersion -like “Version 15*” -and $_.ServerRole -like “Mailbox*”}

ForEach ($server in $MailboxServer)

{

## Collecting user list for the Exchange Server

$UserList = Get-ExchangeServer -Identity $Server | Get-Mailbox -ResultSize Unlimited

## Creating Array to collect each user information

$report = @()

foreach ($User in $UserList)

{

$CASInfo = Get-CasMailbox -identity $user
$MBXInfo = Get-Mailbox -Identity $user
$MBXStat = Get-MailboxStatistics -Identity $user
$ASStat = Get-MobileDeviceStatistics -Mailbox $user

$mbObj = New-Object PSObject
$mbObj | Add-Member -MemberType NoteProperty -Name “DisplayName” -Value $MBXInfo.DisplayName
$mbObj | Add-Member -MemberType NoteProperty -Name “EmailAddress” -Value $MBXInfo.PrimarySmtpAddress
$mbObj | Add-Member -MemberType NoteProperty -Name “ServerName” -Value $MBXStat.ServerName
$mbObj | Add-Member -MemberType NoteProperty -Name “DatabaseName” -Value $MBXStat.DatabaseName
$mbObj | Add-Member -MemberType NoteProperty -Name “MailboxSize” -Value $MBXStat.TotalItemSize
$mbObj | Add-Member -MemberType NoteProperty -Name “ItemCount” -Value $MBXStat.ItemCount
$mbObj | Add-Member -MemberType NoteProperty -Name “ActiveSyncMailboxPolicy” -Value $CASInfo.ActiveSyncMailboxPolicy
$mbObj | Add-Member -MemberType NoteProperty -Name “DeviceType” -Value $ASStat.DeviceType
$mbObj | Add-Member -MemberType NoteProperty -Name “LastSyncAttemptTime” -Value $ASStat.LastSyncAttemptTime
$mbObj | Add-Member -MemberType NoteProperty -Name “LastSuccessSync” -Value $ASStat.LastSuccessSync
$report += $mbObj

}

$rreport += $report

}

## Preparation of User List Report in HTML Format

$rreport | Sort-Object “LastSuccessSync” -descending | Select-Object DisplayName, EmailAddress, ServerName, DatabaseName, MailboxSize, ItemCount, ActiveSyncMailboxPolicy, DeviceType, LastSyncAttemptTime, LastSuccessSync | ConvertTo-Html -body “<h2> Users List Report – Exchange Server 2013</h2>” -head $a | Set-Content c:\temp\Exchange2013UserReport.html

Invoke-Expression C:\temp\Exchange2013UserReport.html

}

}

Advertisements

About Raji Subramanian

Nothing great to say about me...Just want to share my knowledge for others that will be useful at any moment of time when they stuck in critical issue....
This entry was posted in Exchange Server 2013, Script and tagged . Bookmark the permalink.

One Response to Exchange Server 2013 ActiveSync User Report Script

  1. Raja says:

    Hi Raji,
    It’s very useful script. Is it possible to make ActiveSync enabled users list?. from this script, its listing all mailbox. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s