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 = ""
## 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 "" -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 = ""
########### 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 "" -head $a | Set-Content c:\temp\Exchange2013UserReport.html
Invoke-Expression C:\temp\Exchange2013UserReport.html
}
}