Friday, 28 August 2015

Script to generate email statistics report


About the script

This script is written in a simple logic. This will give you very basic statistics about an email messages which are sent and received by your organization. We can enable email function, if you want to get the report as an email format or it will just generate an html file and store it in a location from where you are running this script. You have to give start and end date to capture the statistics.

Script will capture the below parameters

1. Total email sent/received
2. Total email size sent/received
3. Top sender/receiver
4. Top sized email sent/received by your exchange server

Future Enhancements

1. Will add more parameters for the statistics
2. Will add the graph/chart

Script Block

#Script Begins

$StartDate = Read-Host "Enter Start Date in MM/DD/YYYY Format"
$EndDate = Read-Host "Enter End Date in MM/DD/YYYY Format"

# Inputs for Email

$Subject = "Email Statistics Report Generated on" + $(Get-Date).toshortdatestring() + " at " + $(Get-Date).ToshorttimeString()
$FromAddress = "admin@lyncit.net"
$ToAddress = "john@lyncit.net"
$Relay = "ex01.lyncit.net"
$SMTPClient = New-Object System.Net.Mail.smtpClient
$MailMessage = New-Object System.Net.Mail.MailMessage

# Mail Function

$Mail = "True"

$body = $null
$body += '<style>'
$body += '<!-- '
$body += 'body { font: Calibri } '
$body += 'table { font: 11pt Calibri; border: 1px} '
$body += 'td { border: 1px ridge white; padding-left: 1px; padding-right: 1px } '
$body += 'p.header { font: 11pt Verdana; color: DarkBlue }'
$body += 'p.normal { font: 8pt Calibri; color: CadetBlue }'
$body += '-->'
$body += '</style>'
$body += '</head>'
$body += '<body>'
#$body += "<p class=`"header`" align='center'><strong>Email Statistics Report Generated on: " + $(Get-Date).toshortdatestring() + " at " + $(Get-Date).ToshorttimeString()
$body += "<p class=`"header`" align='center'><strong>Email Statistics Report between " + $StartDate + " and " + $EndDate


$msgsent = Get-Exchangeserver | where {$_.isHubTransportServer -eq $true -or $_.isMailboxServer -eq $true} | Get-Messagetrackinglog -start $StartDate -end $EndDate -EventID "RECEIVE" -resultsize unlimited | Select-Object Timestamp,Clienthostname,eventid,source,sender,@{Name="Recipients";Expression={$_.recipients}},Recipientcount,serverhostname,totalbytes,messagesubject

$msgreceive = Get-Exchangeserver | where {$_.isHubTransportServer -eq $true -or $_.isMailboxServer -eq $true} | Get-Messagetrackinglog -start $StartDate -end $EndDate -EventID "DELIVER" -resultsize unlimited | Select-Object Recipients,totalbytes

$msg1 = $msgsent | Measure-Object totalbytes -Maximum -minimum -average -sum
$msgsentcount = $msgsent.count
$msgsentsize = $msg1.sum / (1024 * 1024)
$size = "{0:N2}" -f $msgsentsize + "MB"

$bigsent = $msg1.maximum / (1024 * 1024)
$bigsentmb = "{0:N2}" -f $bigsent + "MB"


$msg2 = $msgreceive | Measure-Object totalbytes -Maximum -minimum -average -sum
$msgrcount = $msgreceive.count
$msgrsize = $msg2.sum / (1024 * 1024)
$rsize = "{0:N2}" -f $msgrsize + "MB"

$bigr = $msg2.maximum / (1024 * 1024)
$bigrmb = "{0:N2}" -f $bigr + "MB"

Write-Host $msgsentcount
Write-Host $size
if ($msgsent -ne $null)
{
        #Table Header
        $body += '<table width=80% align=center>'
        $body += '<td colspan=2 align=center style="background-color: #DCDCDC" border: 1 ; ><strong><font color= Black>' + "SENT EMAILS STATISTICS"  + '</font></strong></td></tr>'
        $body += '<tr><td align="Center" style="background-color: #736F6E" width="13%" border: 1 Groove white;><p class="table" style="color:    white"><b>Parameters</b></p></td>'
        $body += '<td align="Center" style="background-color: #736F6E" width="10%" border: 1 Groove white;><p class="table" style="color:    white"><b>Value</b></p></td>'
$body += '<tr><td align="Center" border: 1 Groove white;>' + "Total Emails Sent" + "</td>"
        $body += '<td align="Center" border: 1 Groove white;>' + $msgsentcount + "</td></tr>"
$body += '<tr><td align="Center" border: 1 Groove white; >' + "Total Sent Emails Size" + "</td>"
$body += '<td align="Center" border: 1 Groove white;>' + $size + "</td></tr>"
$body += '<tr><td align="Center" border: 1 Groove white; >' + "Top sent Email size" + "</td>"
$body += '<td align="Center" border: 1 Groove white;>' + $bigsentmb + "</td></tr>"


$senders = $msgsent | Group-Object Sender | Sort-Object Count -Descending | Select-Object -first "10"


$body += '<td colspan=2 align=center style="background-color: #DCDCDC" border: 1 ; ><strong><font color= Black>' + "Top 10 Senders"  + '</font></strong></td></tr>'
$body += '<tr><td align="Center" style="background-color: #736F6E" width="13%" border: 1 Groove white;><p class="table" style="color:    white"><b>Name</b></p></td>'
        $body += '<td align="Center" style="background-color: #736F6E" width="10%" border: 1 Groove white;><p class="table" style="color:    white"><b>Sent Message Count</b></p></td>'
foreach ($SenderEntry in $senders)
{
 
$name = $senderentry.name
$count = $senderentry.count


$body += '<tr><td align="Center" border: 1 Groove white;>' + $name + "</td>"
            $body += '<td align="Center" border: 1 Groove white; >' + $count + "</td></tr>"

}

$body += '<td colspan=2 align=center style="background-color: #DCDCDC" border: 1 ; ><strong><font color= Black>' + "RECEIVED EMAILS STATISTICS"  + '</font></strong></td></tr>'
        $body += '<tr><td align="Center" style="background-color: #736F6E" width="13%" border: 1 Groove white;><p class="table" style="color:    white"><b>Parameters</b></p></td>'
        $body += '<td align="Center" style="background-color: #736F6E" width="10%" border: 1 Groove white;><p class="table" style="color:    white"><b>Value</b></p></td>'
$body += '<tr><td align="Center" border: 1 Groove white;>' + "Total Emails Received" + "</td>"
        $body += '<td align="Center" border: 1 Groove white;>' + $msgrcount + "</td></tr>"
$body += '<tr><td align="Center" border: 1 Groove white; >' + "Total Received Emails Size" + "</td>"
$body += '<td align="Center" border: 1 Groove white;>' + $rsize + "</td></tr>"
$body += '<tr><td align="Center" border: 1 Groove white; >' + "Top Receive Email size" + "</td>"
$body += '<td align="Center" border: 1 Groove white;>' + $bigrmb + "</td></tr>"


$Userarray = @()
$Measure_Receivers = Measure-Command `
{
 
$msgReceive | foreach {$_.Recipients -split(" ") | foreach {$Userarray += $_} | Out-Null}
    $Userarray = $Userarray | group
    $Receivers = $Userarray | Sort-Object Count -Descending | Select-Object -first "10"
}
$TopRec_file = ""
$TopReceiver = ""
$TopRec = "`n`n"

$body += '<td colspan=2 align=center style="background-color: #DCDCDC" border: 1 ; ><strong><font color= Black>' + "Top 10 Receivers"  + '</font></strong></td></tr>'
$body += '<tr><td align="Center" style="background-color: #736F6E" width="13%" border: 1 Groove white;><p class="table" style="color:    white"><b>Name</b></p></td>'
$body += '<td align="Center" style="background-color: #736F6E" width="10%" border: 1 Groove white;><p class="table" style="color:    white"><b>Email Count</b></p></td>'

foreach ($User in $Receivers)
{
 
$rname = $user.name
$rcount = $user.count

$body += '<tr><td align="Center" border: 1 Groove white;>' + $rname + "</td>"
            $body += '<td align="Center" border: 1 Groove white; >' + $rcount + "</td>"

}
}
             
$body += '</table><br>'



if ($Mail -eq "True")
{
$body += "Report Completed"
$body += '</p></body></html>'

##############################################################
$MailMessage.Subject = " $Subject
$MailMessage.Body = " $Body
$MailMessage.sender = " $FromAddress
$MailMessage.From = " $FromAddress
$MailMessage.To.add(" $ToAddress)
#$MailMessage.CC.add("$CCAddress")
#$MailMessage.CC.add("$CCAddress2")
$MailMessage.IsBodyHTML = $True
$smtpclient.host = " $Relay
$smtpclient.send($MailMessage)
##############################################################
}
else
{
$d = Get-Date
$name = 'Email_Statistics'
$name += $d.year.tostring()
$name += $d.month.tostring()
$name += $d.day.tostring()
$name += '.html'
Set-Content $name -value $body
}

#Script Ends

Sample HTML output



Sample Email output


Tuesday, 25 August 2015

How Skype for Business Differs from Lync 2013


How Skype for Business Differs from Lync 2013 (or not)

Today at the Office 365 Summit, Microsoft gave us a sneak peak at some of the new and improved features that Skype for Business will bring to enterprises. The question burning in my mind before this event was is this just a rebranding exercise, or is Skype for Business a brand new, developed from the ground up application? The answer in short is; Lync 2013 Rebranded, with a few (although cool) additions and many bug and failure fixes.
Throughout the course of this document I will try and explain what the differences are, what is new and what Microsoft are and aren’t saying. I will start with a few headliners, the answers to some of the most asked questions surrounding this launch.
Detailed explanation here

Server-side conversation history in Skype for Business



1. How Conversation history function in previous versions

Conversation History in Lync Server 2013 was device-specific. It stored a record of your conversations in the Lync 2013 client, and in an Outlook folder labeled “Conversation History”, depending on which device you used for that conversation. You’re on a laptop, you get a log in the Conversation History folder. You’re on your phone, you get a log in your phone’s Lync client. 

Whatever the conversation we made from mobile device will not be stored in outlook's conversation history folder and vice versa.
2. What we have in SfB
Now with Skype for Business, instead of device-specific storage, all Conversation History is stored server-side. Which means that all your devices can see the same Conversation History.
3. Pre-requisites
  • Skype for Business Server 2015
  • Exchange 2013 or Exchange Online
  • Exchange Partnership and integration setup and working on both Exchange and Skype for Business. Details here 
  • Test Exchange Connectivity to ensure it configure and working correctly Test-CsExStorageConnectivity -SipUri “sip:John@lyncit.net
  • Enable settings in Skype for Business.
4. How to enable server-side conversation history

Get-CsClientPolicy -Identity global |Set-CsClientPolicy -EnableServerConversationHistory $true

5. Things to check after enabling

Get-CsConversationHistoryConfiguration

Ensure "EnableServerConversationHistory" parameter is "True"

Get-CsMobilityPolicy

Ensure "AllowSaveIMHistory" is enabled

Get-CsClientPolicy

Ensure "DisableSavingIM" is not enabled

Also check exchange integration.

Basic understanding of Session Border Controller (SBC) in Skype for Business




1. What is SBC

SBC stands for Session Border Controller. It’s a discrete hardware device which sits in the perimeter of your network.
It looks at each SIP packet going between your Skype for Business Enterprise Voice network and the external ISP. It determines which packets should be allowed through, and which route they should take.
2. Functions of SBC
SBCs provide multiple security and mediation services within a VoIP environment.
It will monitor the external calls and determines that its legitimate or not.
Taking on this role helps stop a lot of bad things from happening. Within a Skype for Business deployment, SBCs can:
  • Protect the network from Denial of Service attacks, spoofing, and other outside attacks
  • Enable SIP trunking
  • Support interoperability between different endpoints (e.g., different VoIP phone types, as I mentioned in the opening above)
  • ‘Transcoding’ calls – Changing the codec used in a call, depending on the session type (audio, video), device type (tablets, laptops, phones), and bandwidth available
3. Functions of SBC in SfB deployment

To avoid DoS attacks and network break-in attempts.
Each phone can have a different bit rate. And if they do, they can’t connect to one another properly. Unless you use an SBC to bridge them (a process called ‘transrating’).
4. What SBC we should use for SfB
Listed below are the session border controllers that are certified for Skype for Business.
VendorProductSoftware Version
OracleNet-Net 3820ECX6.4.0 MR-5 GA (Build 455)*
SonusSBC 20004.1.1 Build 376*

Note : We can run Skype for Business (or Lync Server) without a Session Border Controller. It’s not mandatory. But it is helpful.


Monday, 24 August 2015

Whats new in Exchange Server 2016




1. Architecture

With Exchange 2016, Microsoft reduced the number of server roles to two: the Mailbox and Edge Transport server roles. 

Mailbox services include all the traditional server components found in the Exchange 2013 Mailbox server role: the Client Access protocols, Transport service, Mailbox databases, and Unified Messaging. The Mailbox server handles all activity for the active mailboxes on that server.
Along with the new Mailbox role, Exchange 2016 now allows you to proxy traffic from Exchange 2013 to Exchange 2016 in addition to Exchange 2016 to Exchange 2013. This new flexibility gives you more control in how you move to Exchange 2016 without having to worry about deploying enough front-end capacity to service new Exchange 2016 servers.

2. Outlook on the web (formerly Outlook Web App)

Outlook Web App is now known as Outlook on the web, which continues to let users access their Exchange mailbox from almost any Web browser.

Supported Web browsers for Outlook on the web in Exchange 2016 are Microsoft Edge, Internet Explorer 11, and the most recent versions of Mozilla Firefox, Google Chrome, and Safari.

3. Support for modern authentication for Outlook

Exchange 2016 brings support the Active Directory Authentication Library (ADAL) authentication model in Outlook clients on Windows, Android, and other platforms. ADAL enables functionality like two-factor authentication to help improve security of your data.

4. MAPI over HTTP 

MAPI over HTTP is now the default protocol that Outlook uses to communicate with Exchange. MAPI over HTTP improves the reliability and stability of the Outlook and Exchange connections by moving the transport layer to the industry-standard HTTP model. clients that don't support it will fall back to Outlook Anywhere (RPC over HTTP).

MAPI over HTTP isn't enable in organizations where the following are true:
  • You're installing Exchange 2016 in an organization that already has Exchange 2013 servers installed.
  • MAPI over HTTP wasn't enabled in Exchange 2013.

5. Document Collaboration

Exchange 2016 will enable Outlook on the web users to link to and share documents stored in OneDrive for Business in an on-premises SharePoint server instead of attaching a file to the message.

If a Word, Excel, or PowerPoint file stored in OneDrive for Business or on-premises SharePoint is included in an email received by a user on Exchange 2016, the user will now have the option of viewing and editing that file in Outlook on the web alongside the message. To do this, you'll need a separate computer running the next version of "Office Web Apps vNext" server in your on-premises organization.

6. Auto-expanding archives

Exchange 2016 offers truly unlimited archiving with auto-expanding archives. In Exchange 2016, you enable an archive mailbox by using one of the same methods you used in Exchange 2013. By default, the initial storage quota for the archive mailbox is 100 GB. When the size of the archive mailbox reaches the 100 GB quota, Exchange 2016 will automatically increase the size of the archive in 50 GB increments.

Note : Users can access the additional storage in the archive mailbox with Outlook 2016 or Outlook on the web. However, Outlook 2013 will only see the initial 100GB of storage.

7. Improved Data Loss Prevention and Transport rules

With a DLP policy in Exchange 2016, you can now identify, monitor, and protect 80 different types of sensitive information

These features are new to transport rules in Exchange 2016:
  • Exchange transport rules can now identify 80 different types of sensitive information. For more information on these sensitive information types, see Sensitive information types inventory.
  • With the new condition Any attachment has these properties, including any of these words, a transport rule can match messages where the specified property of the attached Office document contains specified words. This condition makes it easy to integrate your Exchange transport rules and DLP policies with SharePoint Server, Windows Server 2012 R2 File Classification Infrastructure (FCI), or a third-party classification system.
  • With the new action Notify the recipient with a message, a transport rule can send a notification to the recipient with the text you specify -- for example, you can inform the recipient that the message was rejected by a transport rule, or that it was marked as spam and will be delivered to their Junk Email folder.
  • The action Generate incident report and send it to has been updated so that the incident report can now be sent to multiple distribution lists.




Permanently Clear Previous Mailbox Info for EXO Exchange GUID sync issues

Microsoft is introducing a new parameter that can be called by using the Set-User cmdlet in Exchange Online PowerShell. The new para...