0 votes

Is there a way to make this script (Test-ExchangeServerHealth.ps1) work as a scheduled task or a Custom Command that dispays or emails the output to a specified email address?

http://exchangeserverpro.com/powershell ... hange-2010\

by (350 points)
0

Why don't you just create a Scheduled task on the Exchange server?

0

We may likely make it a scheduled task on an Exchange Server, but we will also want lower level messaging engineers to have the ability to execute the task through the Aaxes portal.

0

Hello Michael,

Yes, it will be possible to run this script in a Custom Command or Scheduled Task and send its output to a specified email using the $Context.SendMail method. For more information on this method, you can read the Sending Emails and SMS section in our SDK.

Our script guy is already working on the task to modify the script to your requirements. I'll update this topic as soon as he comes up with something.

1 Answer

0 votes
by (216k points)

Hello Michael,

Find the modified script below. You can launch the script in Adaxes using a Custom Command with a Run a program or PowerShell script action. When the script completes its job, it sends the results to the user how executes the Custom Command.

Also, if you want to launch the script form Adaxes Web Interface, you can create a Home Page Action that will launch the Custom Command. To evade the object selection page when executing the Custom Command from the Web Interface, you can set up the Home Page Action to always execute for the current user.

To create the Custom Command:

  1. Create a new Custom Command.
  2. On the 2nd step of the Create Custom Command wizard, select User.
  3. On the 3rd step of the wizard, add the Run a program or PowerShell script action and paste the modified PowerShell script that you may find below.
  4. Finish creation of the Custom Command.

To create the Customized Home Page Action:

  1. On the computer, where the Web Interface is installed, start the Web Interface Customization tool.
  2. In the Interface type drop-down list, select the Web Interface you want to configure.
  3. Activate the General tab, select the Actions pane option, and click Configure Home Page Actions.
  4. In the dialog box that appears, click Add...
  5. On the 1st step of the Add Home Page Action wizard that appears, select Custom Command.
  6. Select the Custom Command that you created in the drop-down list that appears next to the Custom Command option.
  7. On the 3rd step of the wizard, select Always perform for the current user to evade the object selection page.
  8. Click Finish.

Here's the modified script that can be used in a Custom Command:

$server = $False # TODO: modify me
# Set to $False to check all servers in the organization.
# If you want to check a specific server, specify the flat name of the computer where the Exchange 
# Server is located in double quotes. For example, $server = "EXCHSERVER"

$now = Get-Date                                           # Used for timestamps
$date = $now.ToShortDateString()                          # Short date format for email message subject
$smtpTo = $Context.Initiator.UserAdsObject.Get("mail")    # To send emails to the operation initiator
$messagesubject = "Exchange Server Health Check - $date"

#...................................
# Initialize
#...................................

#Add Exchange 2010 snapin
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue

#Set recipient scope
if (!(Get-ADServerSettings).ViewEntireForest)
{
    Set-ADServerSettings -ViewEntireForest $true -WarningAction SilentlyContinue
}

#...................................
# Variables
#...................................

[array]$exchangeservers = @()              # Array for the Exchange server or servers to check
[int]$transportqueuehigh = 100             # Change this to set transport queue high threshold
[int]$transportqueuewarn = 80              # Change this to set transport queue warning threshold
$mapitimeout = 20                          # Timeout for each MAPI connectivity test, in seconds
$ip = $null
[array]$summaryreport = @()
[array]$report = @()

#...................................
# Error/Warning Strings
#...................................

$string0 = "Server is not an Exchange server. "
$string1 = "Server is not reachable by ping. "
$string3 = "------ Checking"
$string4 = "Could not test service health. "
$string5 = "Required services not running. "
$string6 = "Could not check queue. "
$string7 = "Public Folder database not mounted. "
$string8 = "Skipping Edge Transport server. "
$string9 = "Mailbox databases not mounted. "
$string10 = "MAPI tests failed. "
$string11 = "Mail flow test failed. "
$string12 = "No Exchange Server 2003 checks performed. "
$string13 = "Server not found in DNS. "

#...................................
# Script
#...................................
# Check if a single server was specified
if ($server)
{
    # Run for single specified server
    try
    {
        $exchangeservers = Get-ExchangeServer $server -ErrorAction Stop
    }
    catch
    {
        # Couldn't find Exchange server of that name
        $Context.LogMessage($_.Exception.Message, "Warning") 

        # Exit because single server was specified and couldn't be found in the organization
        EXIT
    }
}
else
{
    # This is the list of server names to never alert for
    $ignorelist = @()

    $tmpservers = @(Get-ExchangeServer)

    # Remove the servers that are ignored from the list of servers to check
    foreach ($tmpserver in $tmpservers)
    {
        if (!($ignorelist -icontains $tmpserver.name))
        {
            $exchangeservers = $exchangeservers += $tmpserver
        }
    }
}

# Begin the health checks
foreach ($server in $exchangeservers)
{

    $log = $string3 + " " +  $server + "<br/>"

    # Find out some details about the server
    try
    {
        $roles = Get-ExchangeServer $server -ErrorAction Stop
    }
    catch
    {
        $log += '<font color="Orange">' + $_.Exception.Message + " </font> <br/>"
        $roles = $null
    }

    if ($roles -eq $null )
    {
        # Server is not an Exchange server
        $log += '<font color="Orange">' + $string0 + '</font><br/>'
    }
    elseif ( $roles.IsEdgeServer )
    {
        $log += $string8 + '<br/>'
    }
    else
    {
        # Server is an Exchange server, continue the health check

        # Custom object properties
        $serverObj = New-Object PSObject
        $serverObj | Add-Member NoteProperty -Name "Server" -Value $server
        $serverObj | Add-Member NoteProperty -Name "Site" -Value $server.site.name
        $serverObj | Add-Member NoteProperty -Name "DNS" -Value $null
        $serverObj | Add-Member NoteProperty -Name "Ping" -Value $null
        $serverObj | Add-Member NoteProperty -Name "Uptime (hrs)" -Value $null
        $serverObj | Add-Member NoteProperty -Name "Version" -Value $null
        $serverObj | Add-Member NoteProperty -Name "Roles" -Value $null
        $serverObj | Add-Member NoteProperty -Name "CA Services" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "HT Services" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "MB Services" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "UM Services" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "Transport Queue" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "PF DBs Mounted" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "MB DBs Mounted" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "Mail Flow Test" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "MAPI Test" -Value "n/a"
        $serverObj | Add-Member NoteProperty -Name "Error Details" -Value ""
        $serverObj | Add-Member NoteProperty -Name "Warning Details" -Value ""

        # Check server name resolves in DNS
        $log += "DNS Check: "
        try 
        {
            $ip = [System.Net.Dns]::GetHostByName($server).AddressList | Select-Object IPAddressToString -ExpandProperty IPAddressToString
        }
        catch
        {
            $log += '<font color="Orange">' + $_.Exception.Message + ' </font><br/>'
            $ip = $null
        }
        finally    {}

        if ( $ip -ne $null )
        {

            $log += '<font color="Green">Pass </font><br/>'
            $serverObj | Add-Member NoteProperty -Name "DNS" -Value "Pass" -Force

            # Is server online
            $log += "Server up: " 
            $ping = new-object System.Net.NetworkInformation.Ping
            $result = $ping.send($ip)
            if ($result.status.ToString() –eq "Success")
            {
                $log += '<font color="Green">Pass </font><br/>'
                $serverObj | Add-Member NoteProperty -Name "Ping" -Value "Pass" -Force

                # Uptime check
                $uptime = $null
                $laststart = $null

                try 
                {
                    $laststart = [System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject -Class Win32_OperatingSystem -computername $server -ErrorAction Stop).LastBootUpTime)
                }
                catch
                {
                    $log += '<font color="Orange">' + $_.Exception.Message + ' </font><br/>'
                }
                finally    {}

                if ($laststart -eq $null)
                {
                    [string]$uptime = "Unable to retrieve uptime"
                }
                else
                {
                    [int]$uptime = (New-TimeSpan $laststart $now).TotalHours
                    [int]$uptime = "{0:N0}" -f $uptime
                }

                $log += "Uptime (hrs): " 
                Switch ($uptime -gt 23) {
                    $true { $log += '<font color="Green">' + $uptime + '</font><br/>' }
                    $false { $log += '<font color="Orange">' + $uptime + '</font><br/>' }
                    default { $log += '<font color="Orange">' + $uptime + '</font><br/>' }
                    }
                $serverObj | Add-Member NoteProperty -Name "Uptime (hrs)" -Value $uptime -Force    

                # Determine the friendly version number
                $ExVer = $roles.AdminDisplayVersion
                $log += "Server version: " 

                if ($ExVer -like "Version 6.*")
                {
                    $version = "Exchange 2003"
                }

                if ($ExVer -like "Version 8.*")
                {
                    $version = "Exchange 2007"
                }

                if ($ExVer -like "Version 14.*")
                {
                    $version = "Exchange 2010"
                }

                $log += $version + '<br/>'
                $serverObj | Add-Member NoteProperty -Name "Version" -Value $version -Force

                if ($version -eq "Exchange 2003")
                {
                    $log += $string12 + '<br/>'
                    $report = $report + $serverObj
                }
                if ($version -eq "Exchange 2007" -or $version -eq "Exchange 2010")
                {
                    # START - Exchange 2007/2010 Health Checks

                    $log += 'Roles:' + $roles.ServerRole + '<br/>'
                    $serverObj | Add-Member NoteProperty -Name "Roles" -Value $roles.ServerRole -Force

                    $IsEdge = $roles.IsEdgeServer        
                    $IsHub = $roles.IsHubTransportServer
                    $IsCAS = $roles.IsClientAccessServer
                    $IsMB = $roles.IsMailboxServer

                    # START - General Server Health Check
                    # Skipping Edge Transports for the general health check, as firewalls usually get
                    # in the way. If you want to include then, remove this If.
                    if ($IsEdge -ne $true)
                    {
                            # Service health is an array due to how multi-role servers return Test-ServiceHealth status
                            try {
                                $servicehealth = @(Test-ServiceHealth $server -ErrorAction Stop)
                            }
                            catch {
                                $serverObj | Add-Member NoteProperty -Name "Warning Details" -Value ($($serverObj."Warning Details") + $string4) -Force
                                $log += '<font color="Orange">' + $uptime + $string4 + '</font><br/>'
                            }

                            if ($servicehealth)
                            {
                                foreach($s in $servicehealth)
                                {
                                    switch ($s.Role)
                                    {
                                        "Client Access Server Role" { $roleservices = "CA Services" }
                                        "Hub Transport Server Role" { $roleservices = "HT Services" }
                                        "Mailbox Server Role" { $roleservices = "MB Services" }
                                        "Unified Messaging Server Role" { $roleservices = "UM Services" }
                                    }

                                    $log += $s.Role + 'Services: '

                                    switch ($s.RequiredServicesRunning)
                                    {
                                        $true { $svchealth = "Pass"; $log += '<font color="Green">Pass</font><br/>' }
                                        $false {$svchealth = "Fail"; $log += '<font color="Red">Fail</font><br/>'; $serverObj | Add-Member NoteProperty -Name "Error Details" -Value ($($serverObj."Error Details") + $string5) -Force }
                                    }
                                    $serverObj | Add-Member NoteProperty -Name $roleservices -Value $svchealth -Force
                                }
                            }
                    }
                    # END - General Server Health Check

                    # START - Hub Transport Server Check
                    if ($IsHub)
                    {
                        $q = $null
                        $log += "Total Queue: "
                        try {
                            $q = Get-Queue -server $server -ErrorAction Stop
                        }
                        catch {
                            $serverObj | Add-Member NoteProperty -Name "Warning Details" -Value ($($serverObj."Warning Details") + $string6) -Force
                            $log += '<font color="Orange">' + $string6 + '</font><br/>'
                            $log += '<font color="Orange">' + $_.Exception.Message + " </font><br/>"
                        }

                        if ($q)
                        {
                            $qcount = $q | Measure-Object MessageCount -Sum
                            [int]$qlength = $qcount.sum
                            if ($qlength -le $transportqueuewarn)
                            {
                                $log += '<font color="Green">' +  $qlength + '</font><br/>'
                                $serverObj | Add-Member NoteProperty -Name "Transport Queue" -Value "Pass" -Force
                            }
                            elseif ($qlength -gt $transportqueuewarn -and $qlength -lt $transportqueuehigh)
                            {
                                $log +=  '<font color="Orange">' +  $qlength + '</font><br/>'
                                $serverObj | Add-Member NoteProperty -Name "Transport Queue" -Value "Warn" -Force
                            }
                            else
                            {
                                $log += '<font color="Red">' +  $qlength + '</font><br/>'
                                $serverObj | Add-Member NoteProperty -Name "Transport Queue" -Value "Fail" -Force
                            }
                        }
                        else
                        {
                            $serverObj | Add-Member NoteProperty -Name "Transport Queue" -Value "Unknown" -Force
                        }
                    }
                    # END - Hub Transport Server Check

                    # START - Mailbox Server Check
                    if ($IsMB)
                    {
                        # Get the PF and MB databases
                        [array]$pfdbs = @(Get-PublicFolderDatabase -server $server -status -WarningAction SilentlyContinue)
                        [array]$mbdbs = @(Get-MailboxDatabase -server $server -status | Where {$_.Recovery -ne $true})
                        [array]$activedbs = @(Get-MailboxDatabase -status | Where {$_.MountedOnServer -eq ($server.fqdn)})

                        # START - Database Mount Check

                        # Check public folder databases
                        if ($pfdbs.count -gt 0)
                        {
                            $log += "Public Folder databases mounted: "
                            [string]$pfdbstatus = "Pass"
                            [array]$alertdbs = @()
                            foreach ($db in $pfdbs)
                            {
                                if (($db.mounted) -ne $true)
                                {
                                    $pfdbstatus = "Fail"
                                    $alertdbs += $db.name
                                }
                            }

                            $serverObj | Add-Member NoteProperty -Name "PF DBs Mounted" -Value $pfdbstatus -Force

                            if ($alertdbs.count -eq 0)
                            {
                                $log += '<font color="Green">' + $pfdbstatus + '</font><br/>'
                            }
                            else
                            {
                                $log += '<font color="Red">' + $pfdbstatus + '</font><br/>'
                                $serverObj | Add-Member NoteProperty -Name "Error Details" -Value ($($serverObj."Error Details") + $string7) -Force
                                $log += "Offline databases: <br/>" 
                                foreach ($al in $alertdbs)
                                {
                                    $log += '<font color="Red">' + $al + '</font><br/>'
                                }
                            }
                        }

                        # Check mailbox databases
                        if ($mbdbs.count -gt 0)
                        {
                            [string]$mbdbstatus = "Pass"
                            [array]$alertdbs = @()

                            $log += "Mailbox databases mounted: "
                            foreach ($db in $mbdbs)
                            {
                                if (($db.mounted) -ne $true)
                                {
                                    $mbdbstatus = "Fail"
                                    $alertdbs += $db.name
                                }
                            }

                            $serverObj | Add-Member NoteProperty -Name "MB DBs Mounted" -Value $mbdbstatus -Force                            

                            if ($alertdbs.count -eq 0)
                            {
                                $log += '<font color="Green">' + $mbdbstatus + '</font><br/>'
                            }
                            else
                            {
                                $serverObj | Add-Member NoteProperty -Name "Error Details" -Value ($($serverObj."Error Details") + $string9) -Force
                                $log += '<font color="Green">' + $mbdbstatus + '</font><br/>'
                                $log += "Offline databases: "
                                foreach ($al in $alertdbs)
                                {
                                    $log += '<font color="Red">' + $al + '</font><br/>'
                                }
                            }
                        }

                        # END - Database Mount Check

                        # START - MAPI Connectivity Test
                        if ($activedbs.count -gt 0 -or $pfdbs.count -gt 0)
                        {
                            [string]$mbdbstatus = "Pass"
                            [array]$alertdbs = @()
                            $log += "MAPI connectivity: "
                            foreach ($db in $mbdbs)
                            {
                                $mapistatus = Test-MapiConnectivity -Database $db -PerConnectionTimeout $mapitimeout
                                if (($mapistatus.Result.Value) -ne "Success")
                                {
                                    $mbdbstatus = "Fail"
                                    $alertdbs += $db.name
                                }
                            }

                            $serverObj | Add-Member NoteProperty -Name "MAPI Test" -Value $mbdbstatus -Force

                            if ($alertdbs.count -eq 0)
                            {
                                $log += '<font color="Green">' + $mbdbstatus + '</font><br/>'
                            }
                            else
                            {
                                $serverObj | Add-Member NoteProperty -Name "Error Details" -Value ($($serverObj."Error Details") + $string10) -Force
                                $log += '<font color="Red">' + $mbdbstatus + '</font><br/>'
                                $log += "MAPI failed to: <br/>"
                                foreach ($al in $alertdbs)
                                {
                                    $log += '<font color="Red">' + $al + '</font><br/>'
                                }
                            }
                        }
                        # END - MAPI Connectivity Test

                        # START - Mail Flow Test
                        if ($activedbs.count -gt 0 -or $version -eq "Exchange 2007")
                        {

                            $flow = $null
                            $testmailflowresult = $null

                            $log += "Mail flow test: " 
                            try
                            {
                                $flow = Test-Mailflow $server -ErrorAction Stop
                            }
                            catch
                            {
                                $testmailflowresult = $_.Exception.Message
                            }

                            if ($flow)
                            {
                                $testmailflowresult = $flow.testmailflowresult
                            }

                            if ($testmailflowresult -eq "Success")
                            {
                                $log += '<font color="Green">' + $testmailflowresult + '</font><br/>'
                                $serverObj | Add-Member NoteProperty -Name "Mail Flow Test" -Value "Pass" -Force
                            }
                            else
                            {
                                $serverObj | Add-Member NoteProperty -Name "Error Details" -Value ($($serverObj."Error Details") + $string11) -Force
                                $log += '<font color="Red">' + $testmailflowresult + '</font><br/>'
                                $serverObj | Add-Member NoteProperty -Name "Mail Flow Test" -Value "Fail" -Force
                            }
                        }
                        else
                        {
                            $log += "Mail flow test: No active mailbox databases <br/>"
                        }
                        # END - Mail Flow Test
                    }
                    # END - Mailbox Server Check

                }
                # END - Exchange 2007/2010 Health Checks
                $report = $report + $serverObj
            }
            else
            {
                # Server is not up
                $log += '<font color="Orange">' + $string1 + '</font><br/>'
                $serverObj | Add-Member NoteProperty -Name "Error Details" -Value ($($serverObj."Error Details") + $string1) -Force
                $serverObj | Add-Member NoteProperty -Name "Ping" -Value "Fail" -Force
                $report = $report + $serverObj
            }
        }
        else
        {
            $log += '<font color="Red">Fail </font><br/>'
            $log += '<font color="Orange">' + $string13 + " </font><br/>"
            $serverObj | Add-Member NoteProperty -Name "Error Details" -Value ($($serverObj."Error Details") + $string13) -Force
            $serverObj | Add-Member NoteProperty -Name "DNS" -Value "Fail" -Force
            $report = $report + $serverObj
        }
    }    
}

# Generate the report
# Get report generation timestamp
$reportime = Get-Date

# Generate report summary
$summaryreport = $report | select Server,"Error Details","Warning Details" | Where {$_."Error Details" -ne "" -or $_."Warning Details" -ne ""}

# Create HTML Report
# Common HTML head and styles
$htmlhead="<html>
            <style>
            BODY{font-family: Arial; font-size: 8pt;}
            H1{font-size: 16px;}
            H2{font-size: 14px;}
            H3{font-size: 12px;}
            TABLE{border: 1px solid black; border-collapse: collapse; font-size: 8pt;}
            TH{border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;}
            TD{border: 1px solid black; padding: 5px; }
            td.pass{background: #7FFF00;}
            td.warn{background: #FFE600;}
            td.fail{background: #FF0000; color: #ffffff;}
            </style>
            <body>
            <h1 align=""center"">Exchange Server Health Check Report</h1>
            <h3 align=""center"">Generated: $reportime</h3>"

if ($summaryreport)
{
    $summaryhtml = "<h3>Exchange Server Health Check Summary</h3>
                    <p>The following errors and warnings were detected.</p>
                    <p>
                    <table>
                    <tr>
                    <th>Server</th>
                    <th>Errors</th>
                    <th>Warnings</th>
                    </tr>"
    foreach ($reportline in $summaryreport)
    {
        $htmltablerow = "<tr>"
                    $htmltablerow = $htmltablerow + "<td>$($reportline.server)</td>"
                    $htmltablerow = $htmltablerow + "<td>$($reportline."Error Details")</td>"
                    $htmltablerow = $htmltablerow + "<td>$($reportline."Warning Details")</td>"

                    $summaryhtml = $summaryhtml + $htmltablerow
    }
    $summaryhtml = $summaryhtml + "</table></p>"
}
else
{
    $summaryhtml = "<h3>Exchange Server Health Check Summary</h3>
                    <p>No Exchange server health alerts or warnings.</p>"
}

if ($report)
{
    # Exchange 2007/2010 Report Table Header
    $htmltableheader = "<h3>Exchange Server 2007/2010 Health</h3>
                        <p>
                        <table>
                        <tr>
                        <th>Server</th>
                        <th>Site</th>
                        <th>Roles</th>
                        <th>Version</th>
                        <th>DNS</th>
                        <th>Ping</th>
                        <th>Uptime (hrs)</th>
                        <th>CA Services</th>
                        <th>HT Services</th>
                        <th>MB Services</th>
                        <th>UM Services</th>
                        <th>Transport Queue</th>
                        <th>PF DBs Mounted</th>
                        <th>MB DBs Mounted</th>
                        <th>MAPI Test</th>
                        <th>Mail Flow Test</th>
                        </tr>"

    # Exchange 2007/2010 Report Table
    $htmltable = $htmltable + $htmltableheader

    foreach ($reportline in $report)
    {
        $htmltablerow = "<tr>"
        $htmltablerow = $htmltablerow + "<td>$($reportline.server)</td>"
        $htmltablerow = $htmltablerow + "<td>$($reportline.site)</td>"
        $htmltablerow = $htmltablerow + "<td>$($reportline.roles)</td>"
        $htmltablerow = $htmltablerow + "<td>$($reportline.version)</td>"

        switch ($($reportline.dns))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline.dns)</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline.dns)</td>"}
        }

        switch ($($reportline.ping))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline.ping)</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline.ping)</td>"}
        }

        if ($($reportline."uptime (hrs)") -eq "Access Denied")
        {
            $htmltablerow = $htmltablerow + "<td class=""warn"">Access Denied</td>"
        }
        else
        {
            $hours = [int]$($reportline."uptime (hrs)")
            if ($hours -le 24)
            {
                $htmltablerow = $htmltablerow + "<td class=""warn"">$hours</td>"
            }
            else
            {
                $htmltablerow = $htmltablerow + "<td class=""pass"">$hours</td>"
            }
        }

        switch ($($reportline."CA Services"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."CA Services")</td>"}
            "Warn" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."CA Services")</td>"}
            "Access Denied" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."CA Services")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."CA Services")</td>"}
            default {$htmltablerow = $htmltablerow + "<td>$($reportline."CA Services")</td>"}
        }

        switch ($($reportline."HT Services"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."HT Services")</td>"}
            "Warn" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."HT Services")</td>"}
            "Access Denied" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."HT Services")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."HT Services")</td>"}
            default {$htmltablerow = $htmltablerow + "<td>$($reportline."HT Services")</td>"}
        }

        switch ($($reportline."MB Services"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."MB Services")</td>"}
            "Warn" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."MB Services")</td>"}
            "Access Denied" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."MB Services")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."MB Services")</td>"}
            default {$htmltablerow = $htmltablerow + "<td>$($reportline."MB Services")</td>"}
        }

        switch ($($reportline."UM Services"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."UM Services")</td>"}
            "Warn" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."UM Services")</td>"}
            "Access Denied" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."UM Services")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."UM Services")</td>"}
            default {$htmltablerow = $htmltablerow + "<td>$($reportline."UM Services")</td>"}
        }

        switch ($($reportline."Transport Queue"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."Transport Queue")</td>"}
            "Warn" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."Transport Queue")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."Transport Queue")</td>"}
            "Unknown" {$htmltablerow = $htmltablerow + "<td class=""warn"">$($reportline."Transport Queue")</td>"}
            default {$htmltablerow = $htmltablerow + "<td >$($reportline."Transport Queue")</td>"}
        }

        switch ($($reportline."PF DBs Mounted"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."PF DBs Mounted")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."PF DBs Mounted")</td>"}
            default {$htmltablerow = $htmltablerow + "<td>$($reportline."PF DBs Mounted")</td>"}
        }

        switch ($($reportline."MB DBs Mounted"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."MB DBs Mounted")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."MB DBs Mounted")</td>"}
            default {$htmltablerow = $htmltablerow + "<td>$($reportline."MB DBs Mounted")</td>"}
        }

        switch ($($reportline."MAPI Test"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."MAPI Test")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."MAPI Test")</td>"}
            default {$htmltablerow = $htmltablerow + "<td>$($reportline."MAPI Test")</td>"}
        }

        switch ($($reportline."Mail Flow Test"))
        {
            "Pass" {$htmltablerow = $htmltablerow + "<td class=""pass"">$($reportline."Mail Flow Test")</td>"}
            "Fail" {$htmltablerow = $htmltablerow + "<td class=""fail"">$($reportline."Mail Flow Test")</td>"}
            default {$htmltablerow = $htmltablerow + "<td>$($reportline."Mail Flow Test")</td>"}
        }

        $htmltablerow = $htmltablerow + "</tr>"

        $htmltable = $htmltable + $htmltablerow
    }
    $htmltable = $htmltable + "</table></p>" + "<p><h3>" + $log + "</h3><p>"
}

$htmltail = "</body>
            </html>"

$htmlreport = $htmlhead + $summaryhtml + $htmltable + $htmltail

# Send email message
$Context.SendMail($smtpto, $messageSubject, $NULL, $htmlreport)
0

I'm receiving the following error. Can you assist with this?

Run PowerShell script 'Exchange Health Check' for the user

Exception calling "Get" with "1" argument(s): "The 'mail' property cannot be found in the cache." Exception calling "SendMail" with "4" argument(s): "Parameter must be a non empty string. Parameter name: toAddress"

0

Michael,

This error means that the user account with the credentials of which you are trying to launch the Custom Command does not have the Email property specified. The script tries to email the report to this e-mail.

0

Thank you that was the issue. The script is working now!

Related questions

0 votes
0 answers

Hi, relatively new to Adaxes. We use a third party for our mail archiving solution for this to work account we have for this 3rd party needs full access to every mailbox. On ... I get stuck at the rest. Would anyone be able to assist? Thanks in advance Gary

asked Apr 29, 2020 by caoky (20 points)
0 votes
1 answer

Hi, relatively new to Adaxes. We use a third party for our mail archiving solution for this to work account we have for this 3rd party needs full access to every mailbox. On ... I get stuck at the rest. Would anyone be able to assist? Thanks in advance Gary

asked Dec 12, 2017 by gazoco (490 points)
0 votes
1 answer

We're looking at adding a powershell script to check for duplicate Exchange Aliases within our exchange organization prior to a user modification. We've noticed that ... .LogMessage($uniqueUsername + "@domain.com", "Error"); Thanks for your assistance!

asked Aug 14, 2014 by VTPatsFan (610 points)
0 votes
1 answer

For creating a computer object, we want to check if the entered CN is already used in our AD. And for that we want to use a powershell script. An other dot ... powershell script should be start before creating the computer object, right? Thanks for your help.

asked Jun 4 by KEME (80 points)
0 votes
1 answer

Hello, Based on your script, we check whether there is already a request. However, we often get the following error and do not know why. Can you help us? ... Cannot compare "Softerra.Adaxes.Adsi.Search.AdmSearchResult" because it is not IComparable. Thank you

asked Apr 16 by DRiVSSi (320 points)
3,589 questions
3,278 answers
8,303 comments
548,107 users