AK578442

Monitor_AK578442 (UnitMonitor)

Exchange Web Services message size limit is non-default

Knowledge Base article:

External

http://go.microsoft.com/fwlink/?LinkId=242946

Element properties:

TargetMicrosoft.KnowledgeServices.Exchange.2010.ClientAccessRole
Parent MonitorSystem.Health.ConfigurationState
CategoryAlert
EnabledTrue
Alert GenerateTrue
Alert SeverityWarning
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.KnowledgeServices.Library.PowerShellMonitorEx
RemotableTrue
AccessibilityPublic
Alert Message
Exchange Web Services message size limit is non-default
<Details>
<Content>You can modify message size limits to increase or decrease the size of e-mail messages that clients may send or receive. Please verify that the size limit is not too small or too large. For more information, see the article at the link below.</Content>
<CollectedInformation>
<Info>
<Name>MaxAllowedContentLength</Name>
<Value>{0}</Value>
</Info>
<Info>
<Name>MaxRequestLength</Name>
<Value>{1}</Value>
</Info>
<Info>
<Name>MaxReceivedMessageSize</Name>
<Value>{2}</Value>
</Info>
</CollectedInformation>
</Details>
RunAsDefault
CommentSupportTopic=TBD;VersionNumber=1.0.0.0;

Source Code:

<UnitMonitor ID="Monitor_AK578442" Comment="SupportTopic=TBD;VersionNumber=1.0.0.0;" Accessibility="Public" Enabled="true" Target="MicrosoftKnowledgeServicesExchange2010Library!Microsoft.KnowledgeServices.Exchange.2010.ClientAccessRole" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="true" Priority="Normal" TypeID="KnowledgeServicesLibrary!Microsoft.KnowledgeServices.Library.PowerShellMonitorEx" ConfirmDelivery="true">
<Category>Alert</Category>
<AlertSettings AlertMessage="MonitorMessage4366505d8ca24b86a5d5b000813ae8a7">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Warning</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Data/Context/Property[@Name='MaxAllowedContentLength']$</AlertParameter1>
<AlertParameter2>$Data/Context/Property[@Name='MaxRequestLength']$</AlertParameter2>
<AlertParameter3>$Data/Context/Property[@Name='MaxReceivedMessageSize']$</AlertParameter3>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
</OperationalStates>
<Configuration>
<ScriptName>AK578442.ps1</ScriptName>
<Parameters>
<Parameter>
<Name>ServerName</Name>
<Value>$Target/Host/Property[Type="MicrosoftKnowledgeServicesExchange2010Library!Microsoft.KnowledgeServices.Exchange.2010.Server"]/Name$</Value>
</Parameter>
<Parameter>
<Name>ExchangeMajorVersion</Name>
<Value>$Target/Host/Host/Property[Type="MicrosoftKnowledgeServicesExchange2010Library!Microsoft.KnowledgeServices.Exchange.2010.Installation"]/SetupProductMajor$</Value>
</Parameter>
<Parameter>
<Name>ExchangeMinorVersion</Name>
<Value>$Target/Host/Host/Property[Type="MicrosoftKnowledgeServicesExchange2010Library!Microsoft.KnowledgeServices.Exchange.2010.Installation"]/SetupProductMinor$</Value>
</Parameter>
</Parameters>
<ScriptBody><Script>


param($ServerName,$ExchangeMajorVersion,$ExchangeMinorVersion)

$ErrorActionPreference = "Stop"

# Set up the arguments
$scriptargs = new-object psobject
$scriptargs | add-member NoteProperty "ServerName" $ServerName
$scriptargs | add-member NoteProperty "ExchangeMajorVersion" $ExchangeMajorVersion
$scriptargs | add-member NoteProperty "ExchangeMinorVersion" $ExchangeMinorVersion

# Set up the output
$global:scriptoutput = new-object psobject
$scriptoutput | add-member NoteProperty "HasIssue" $false
$scriptoutput | add-member NoteProperty "MaxAllowedContentLength" ""
$scriptoutput | add-member NoteProperty "MaxRequestLength" ""
$scriptoutput | add-member NoteProperty "MaxReceivedMessageSize" ""
#-----------------------------------------------------
# MAIN CODE SECTION
#-----------------------------------------------------

# Environment

$scriptenv = new-object psobject
$scriptenv | add-member NoteProperty "ErrorFlag" $null
$scriptenv | add-member NoteProperty "AreTheAttributesDefaultValue" $true
$scriptenv | add-member NoteProperty "WebConfigContent" $null
$scriptenv | add-member NoteProperty "ExchangeVersion" $null
$scriptenv | add-member NoteProperty "DefaultMaxAllowedContentLength" $null
$scriptenv | add-member NoteProperty "DefaultMaxRequestLength" $null
$scriptenv | add-member NoteProperty "DefalutMaxReceivedMessageSize" $null

# Helper functions
# Function to get the default value of maxAllowedContentLength,maxRequestLength &amp; maxReceivedMessageSize
# Reference:
# http://technet.microsoft.com/en-us/library/hh135098.aspx (Exchange Versions)
Function Set-DefaultAttributeValue() {
$scriptenv.DefaultMaxRequestLength = 2097151
if($scriptargs.ExchangeMajorVersion -eq 14 -and $scriptargs.ExchangeMinorVersion -eq 1){
$scriptenv.ExchangeVersion = "SP1"
$scriptenv.DefaultMaxAllowedContentLength = 35000000
$scriptenv.DefalutMaxReceivedMessageSize = 35000000
}
elseif($scriptargs.ExchangeMajorVersion -eq 14 -and $scriptargs.ExchangeMinorVersion -eq 0) {
$scriptenv.ExchangeVersion = "RTM"
$scriptenv.DefaultMaxAllowedContentLength = 13600000
$scriptenv.DefalutMaxReceivedMessageSize = 13600000
}
}

# Function to check if the maxAllowedContentLength,maxRequestLength or maxReceivedMessageSize set to default value
Function Check-AreTheAttributesDefaultValue($xmlContent){
$AreTheAttributesDefaultValue = $true
Set-DefaultAttributeValue
$Entrys = $xmlContent.configuration."system.serviceModel".bindings.customBinding.binding | where {$_.Name.StartsWith("EWS")}
$scriptoutput.MaxReceivedMessageSize = ""
Foreach($Entry in $Entrys){
If($Entry.httpsTransport.maxReceivedMessageSize -ne $null){
$scriptoutput.MaxReceivedMessageSize += $Entry.Name + ": " + $Entry.httpsTransport.maxReceivedMessageSize + "`n"
If($Entry.httpsTransport.maxReceivedMessageSize -ne $scriptenv.DefalutMaxReceivedMessageSize){
$AreTheAttributesDefaultValue = $false
}
}
If($Entry.httpTransport.maxReceivedMessageSize -ne $null ){
$scriptoutput.MaxReceivedMessageSize += $Entry.Name + ": " + $Entry.httpTransport.maxReceivedMessageSize + "`n"
if($Entry.httpTransport.maxReceivedMessageSize -ne $scriptenv.DefalutMaxReceivedMessageSize){
$AreTheAttributesDefaultValue = $false
}
}
}
$scriptoutput.MaxAllowedContentLength = $scriptenv.WebConfigContent.configuration."system.Webserver".security.requestFiltering.requestLimits.maxAllowedContentLength
If($scriptoutput.MaxAllowedContentLength -eq $null){
$scriptoutput.MaxAllowedContentLength = $scriptenv.DefaultMaxAllowedContentLength
}
ElseIf($scriptoutput.MaxAllowedContentLength -ne $scriptenv.DefaultMaxAllowedContentLength){
$AreTheAttributesDefaultValue = $false
}
$scriptoutput.MaxRequestLength = $scriptenv.WebConfigContent.configuration."system.web".httpRuntime.maxRequestLength
If($scriptoutput.MaxRequestLength -eq $null){
$scriptoutput.MaxRequestLength = $scriptenv.DefaultMaxRequestLength
}
ElseIf($scriptoutput.MaxRequestLength -ne $scriptenv.DefaultMaxRequestLength){
$AreTheAttributesDefaultValue = $false
}
$AreTheAttributesDefaultValue
}

# function to get Web.config content
Function Get-WebConfigContent() {
$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $scriptargs.ServerName)
$key = $baseKey.OpenSubKey("SOFTWARE\Microsoft\ExchangeServer\v14\Setup", $false)
if ($key -ne $null)
{
$ConfigFileLocation = $key.GetValue("MsiInstallPath", "")
}
$ConfigFilePath = [System.IO.Path]::Combine($ConfigFileLocation,"ClientAccess\exchweb\ews\Web.config")
[XML]$Configfile = Get-Content $ConfigFilePath -ErrorAction SilentlyContinue
$Configfile
}

# Main function
Function AdvisorRule($scriptargs, $scriptoutput) {
# All parameters should be populated outside of the main function.
# The mian function should only include the detection logic so that it can be easyly reused by the Atlanta authoring tool.

trap [Exception] {
$scriptenv.ErrorFlag = $true
continue
}


# Initialize parameters
$scriptenv.ErrorFlag = $false
$scriptenv.AreTheAttributesDefaultValue = $true
$scriptenv.WebConfigContent = Get-WebConfigContent

$scriptoutput.HasIssue = $false

# Set parameter values
$scriptenv.AreTheAttributesDefaultValue = Check-AreTheAttributesDefaultValue $scriptenv.WebConfigContent

# # Detection Logic
# #If Exchange Server 2010 RTM or SP1 Exchange Web Services message size limit is non-defaul
if($scriptenv.ExchangeVersion -eq "RTM" -or $scriptenv.ExchangeVersion -eq "SP1"){
If($scriptenv.AreTheAttributesDefaultValue -ne $true){
If($scriptenv.ErrorFlag -ne $true){
#Raise Alert
$scriptoutput.HasIssue = $true
}
}
}
}
AdvisorRule $scriptargs $scriptoutput

# set the output
$mom = new-object -comobject "MOM.ScriptAPI"
$bag = $mom.CreatePropertyBag()

if ($scriptoutput.HasIssue -ne $null)
{
$bag.AddValue("HasIssue", $scriptoutput.HasIssue)
}

if ($scriptoutput.MaxAllowedContentLength -ne $null)
{
$bag.AddValue("MaxAllowedContentLength", $scriptoutput.MaxAllowedContentLength)
}

if ($scriptoutput.MaxRequestLength -ne $null)
{
$bag.AddValue("MaxRequestLength", $scriptoutput.MaxRequestLength)
}

if ($scriptoutput.MaxReceivedMessageSize -ne $null)
{
$bag.AddValue("MaxReceivedMessageSize", $scriptoutput.MaxReceivedMessageSize)
}

$bag

</Script></ScriptBody>
<SnapIns>
<SnapIn>Microsoft.Exchange.Management.PowerShell.E2010</SnapIn>
</SnapIns>
<TimeoutSeconds>300</TimeoutSeconds>
<Schedule>86375</Schedule>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<Not>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</Not>
</SuccessExpression>
</Configuration>
</UnitMonitor>