A new project to collect all the data from Exchange Systems and put it all into a neat little zip folder that can be collected and analyzed. I plan to make it functional for all versions of PowerShell based Exchange, but for now… Take a gander at what I’ve got done so far. I’ll be updating this post throughout the weekend until my E15 is at v 0.5 or so… Which will be when I’m ready to run it outside of my test environment and see how it looks.

Function Test-MailboxServer {
    Param(
        [string]$date
    )
    New-Item .\Results$date\Mailbox -ItemType Directory
    $mailServers = Get-MailboxServer
    foreach ($mailServer in $mailServers) {
        #Basic Network Info
        Get-NetworkInfo -serverName $mailServer.Name -serverType "Mailbox" -date $date
        
        #Health Checks
        
        Write-Host "Getting Basic Information about Mailbox Server Health."
        $MRSHealth = Test-MRSHealth -Identity $mailServer.Name
        $AssistHealth = Test-AssistantHealth -ServerName $mailServer.Name
        $SearchHealth = Test-ExchangeSearch -Server $mailServer.Name
        $MAPIHealth = Test-MapiConnectivity -Server $mailServer.Name
        $ReplHealth = Test-ReplicationHealth -Identity $mailServer.Name
        #Note: The below email is one that exists and receives email, but isn't monitored... If you want to change it feel free!
        $MailFlowHealth = Test-Mailflow -TargetEmailAddress "nic.holmes@mailinator.com"
        $SMTPHealth = Test-SmtpConnectivity -Identity $mailServer.Name
        $ReplStatus = Get-MailboxDatabaseCopyStatus -Server $mailServer.Name
        $calConnect = Test-CalendarConnectivity -MailboxServer $mailServer.name
        $ecpConn = Test-EcpConnectivity -MailboxServer $mailServer.Name
        $imapConn = Test-ImapConnectivity -MailboxServer $mailServer.Name
        $owaHealth = Test-OwaConnectivity -MailboxServer $mailServer.Name
        $popHealth = Test-PopConnectivity -MailboxServer $mailServer.Name
        $serviceHealth = Test-ServiceHealth -Server $mailServer.Name
        if ((Get-Service -ComputerName $mailServer.Name -Name MSExchangeHM).Status -eq "Running") {
            $OutlookAnyHealth = Test-OutlookConnectivity -ProbeIdentity OutlookRPCDeepTestProbe -Hostname $mailServer.Name
            $MapiHttpHealth = Test-OutlookConnectivity -ProbeIdentity OutlookMapiHttpDeepTestProbe -Hostname $mailServer.Name
        }
        else {
            Invoke-Command -ComputerName $mailServer.Name -ScriptBlock { Start-Service -Name MSExchangeHM }
            $OutlookAnyHealth = Test-OutlookConnectivity -ProbeIdentity OutlookRPCDeepTestProbe -Hostname $mailServer.Name
            $MapiHttpHealth = Test-OutlookConnectivity -ProbeIdentity OutlookMapiHttpDeepTestProbe -Hostname $mailServer.Name
            Invoke-Command -ComputerName $mailServer.Name -ScriptBlock { Stop-Service -Name MSExchangeHM }
        }
        
        #Gather Configuration Data

        Write-Host "Getting Configuration Info on Mailbox Servers"
        $Databases = Get-MailboxDatabase -Server $mailServer.Name
        $storeUsageStat = Get-StoreUsageStatistics -Server $mailServer.Name
        $mailboxes = Get-Mailbox -Server $mailServer.Name
        $mailboxStats = $mailboxes | Get-MailboxStatistics | Sort-Object -Property TotalItemSize -Descending
        $largeMailboxes = @($mailboxStats[0], $mailboxStats[1], $mailboxStats[2], $mailboxStats[3], $mailboxStats[4])

    }
}

Function Test-ClientAccessServer {
    Param(
        [string]$date
    )
    New-Item .\results$date\CAS -ItemType Directory
    $CAServers = Get-ClientAccessServer
    #Checking for the EXTest_Account, if it doesn't exist it creates it and generates a random password
    Write-Host "Looking for EXtest Account."
    $ErrorActionPreference = 'silentlycontinue'
    if ((Get-Mailbox "*extest*") -eq $null) {
        Write-Host -ForegroundColor Red "Unable to find EXTest account! Creating it now."
        $ascii = $NULL
        For ($a = 33; $a –le 126; $a++) {
            $ascii += , [char][byte]$a 
        }
        For ($loop = 1; $loop –le 20; $loop++) {
            $TempPassword += ($ascii | Get-Random)
        }
        $ExPass = ConvertTo-SecureString $TempPassword -AsPlainText -Force
        $currentLoc = Get-Location
        Set-Location $env:ExchangeInstallPath\scripts
        .\new-TestCasConnectivityUser.ps1 -Password $ExPass
        Set-Location $currentLoc
    }
    $ErrorActionPreference = 'continue'
    foreach ($CAServer in $CAServers) {

        #Health Checks

        Write-Host "Getting Basic information about CAS Health"
        $actSyncHealth = Test-ActiveSyncConnectivity
        $calConnect = Test-CalendarConnectivity -ClientAccessServer $CAServer.name
        $ecpConn = Test-EcpConnectivity -ClientAccessServer $CAServer.Name
        $imapConn = Test-ImapConnectivity -ClientAccessServer $CAServer.Name
        $owaHealth = Test-OwaConnectivity -ClientAccessServer $CAServer.Name
        $popHealth = Test-PopConnectivity -ClientAccessServer $CAServer.Name
        if ((Get-Service -ComputerName $CAServer.Name -Name MSExchangeHM).Status -eq "Running") {
            $outlookAnyHealth = Test-OutlookConnectivity -ProbeIdentity OutlookRpcCtpProbe -Hostname $CAServer.Name
            $mapiHttpHealth = Test-OutlookConnectivity -ProbeIdentity OutlookMapiHttpCtpProbe -Hostname $CAServer.Name
        }
        else {
            Invoke-Command -ComputerName $CAServer.Name -ScriptBlock { Start-Service -Name MSExchangeHM }
            $outlookAnyHealth = Test-OutlookConnectivity -ProbeIdentity OutlookRpcCtpProbe -Hostname $CAServer.Name
            $mapiHttpHealth = Test-OutlookConnectivity -ProbeIdentity OutlookMapiHttpCtpProbe -Hostname $CAServer.Name
            Invoke-Command -ComputerName $CAServer.Name -ScriptBlock { Stop-Service -Name MSExchangeHM }
        }
        $serviceHealth = Get-ServiceHealth -Server $CAServer.Name

        #Get information

        $actSyncVirDir = Get-ActiveSyncVirtualDirectory -Server $CAServer.Name
        $eCPVirDir = Get-EcpVirtualDirectory -Server $CAServer.Name
        $mapiVirDir = Get-MapiVirtualDirectory -Server $CAServers.Name
        $oABVirDir = Get-OabVirtualDirectory -Server $CAServer.Name
        $oWAVirDir = Get-OwaVirtualDirectory -Server $CAServer.Name
        $eWSVirDir = Get-WebServicesVirtualDirectory -Server $CAServer.Name

    }
}

Function Get-NetworkInfo {
    Param(
        [string]$serverName,
        [string]$serverType,
        [string]$date
    )
    Write-Host "Gathering Network Information for $serverName"
    $netConfig = Invoke-Command -ComputerName $serverName -ScriptBlock { ipconfig /all }
    $ping = $null
    $ping = Invoke-Command -ComputerName $serverName -ScriptBlock { ping google.com }
    $tracert = $null
    if ($ping -like "*Reply from*") {
        $tracert = $ping = Invoke-Command -ComputerName $serverName -ScriptBlock { tracert google.com }
    }
    else {
        $pingError = "No available connection to the internet for $serverName !"
        Write-Host -ForegroundColor Red "No available connection to the internet!"
    }
    Write-Host "Outputting Information to file"
    "IP Config", $netConfig | Out-File .\Results$date\$serverType\$($serverName)NetConfig.txt
    "Ping Results", $ping | Out-File .\Results$date\$serverType\$($serverName)NetConfig.txt -Append
    if ($tracert) {
        "Trace Route", $tracert | Out-File .\Results$date\$serverType\$($serverName)NetConfig.txt -Append
    }
    else {
        $pingError | Out-File .\Results$date\$serverType\$($serverName)NetConfig.txt -Append
    }
}


Function Get-OrganizationInfo {
    Param(
        [string]$date
    )

    #Creating Org Directory
    New-Item .\results$date\OrgConfig -ItemType Directory

    #Collecting Org Data
    $owaMailPolicy = Get-OwaMailboxPolicy
    $activeSyncMailPol = Get-MobileDeviceMailboxPolicy
    $cASArray = Get-ClientAccessArray
    $mailboxes = Get-Mailbox -ResultSize Unlimited
    $mailboxSize += ($mailboxes | Get-MailboxStatistics).TotalItemSize.Value
    $mailboxSize | % { $totalSize = $totalSize + $_ }
    $ActSyncDev = $mailbox | Get-MobileDevice


}
Expand

Leave a Reply

Your email address will not be published. Required fields are marked *