Hey everyone! So I’ve gotten the base version for Exchange 2013 completed, though I still haven’t added any of the HTML processing. I’d like to get that going this weekend, though I’m not super familiar with HTML tables in PowerShell, so it could take me some time. Anyway, this will give you quite a dump of all the info on your Exchange server if you are looking for it!

Function Test-E15MailboxServer {
    Param(
        [string]$date,
        [string]$mailServer
    )
    New-Item .\Results$date\Mailbox -ItemType Directory
    #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])


    #Outputting Data!
    Write-Host "Outputting Data about $mailServer.Name" 

    "Mailbox Replication Health", $mRSHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt
    "Mailbox Assistant Health", $assistHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "Search Health", $SearchHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "MAPI Health", $mAPIHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "Replication Health", $replHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "Mailflow Health Check", $mailFlowHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "SMTP Send receive health", $sMTPHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "Replication Status", $replStatus | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "Calendar Health", $calConnect | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "Exchange Control Panel Health", $ecpConn | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "IMAP Health", $imapConn | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "OWA Health", $owaHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "POP3 Health", $popHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "Service Health", $serviceHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "Outlook Anywhere Health", $outlookAnyHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append
    "MAPI over HTTP Health", $mapiHttpHealth | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name).txt -Append

    #Mailbox data

    $databases | Export-Csv -Path .\Results$date\Mailbox\$($mailServer.Name)databases.csv
    $storeUsageStat | Out-File -FilePath .\Results$date\Mailbox\$($mailServer.Name)usage.txt
    $mailboxes | Export-Csv -Path .\Results$date\Mailbox\$($mailServer.Name)mailboxes.csv
    $largeMailboxes | Export-Csv -Path .\Results$date\Mailbox\$($mailServer.Name)largemailboxes.csv

    #Writing Event Logs

    $eventLogs = Get-EventLog -LogName Application -ComputerName $mailServer.Name -Source MSExchange*
    $eventLogs | Export-Csv -Path .\results$date\CAS\$($mailServer.name)eventlog.csv


}

Function Test-E15ClientAccessServer {
    Param(
        [string]$date,
        [string]$cAServer
    )
    New-Item .\results$date\CAS -ItemType Directory
    #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'

    #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 $cAServer.Name
    $oABVirDir = Get-OabVirtualDirectory -Server $cAServer.Name
    $oWAVirDir = Get-OwaVirtualDirectory -Server $cAServer.Name
    $eWSVirDir = Get-WebServicesVirtualDirectory -Server $cAServer.Name
    $outlookAnywhereVirDir = Get-OutlookAnywhere -Server $cAServer.Name

    #Output data
    Write-Host "Outputting Data for $cAServer.Name"
        
    "ActiveSync Health", $actSyncHealth | Out-File .\results$date\CAS\$($cAServer.name).txt
    "Calendar Connectivity Health", $calConnect | Out-File .\results$date\CAS\$($cAServer.name).txt -Append
    "Exchange Control Panel Health", $ecpConn | Out-File .\results$date\CAS\$($cAServer.name).txt -Append
    "IMAP Connectivity", $imapConn | Out-File .\results$date\CAS\$($cAServer.name).txt -Append
    "OWA Health Check", $owaHealth | Out-File .\results$date\CAS\$($cAServer.name).txt -Append
    "POP3 Connectivity check", $popHealth | Out-File .\results$date\CAS\$($cAServer.name).txt -Append
    "Outlook Anywhere Health Check", $outlookAnyHealth | Out-File .\results$date\CAS\$($cAServer.name).txt -Append
    "MAPI over HTTP Health Check", $mapiHttpHealth | Out-File .\results$date\CAS\$($cAServer.name).txt -Append

    #Outputting Virutal Directories

    "ActiveSync Virtual Directory", $actSyncVirDir | Out-File .\results$date\CAS\$($cAServer.name)VirDir.txt 
    "Exchange Control Panel Directory", $eCPVirDir | Out-File .\results$date\CAS\$($cAServer.name)VirDir.txt -Append
    "MAPI over HTTP Directory", $mapiVirDir | Out-File .\results$date\CAS\$($cAServer.name)VirDir.txt -Append
    "Offline Address Book Virtual Directory", $oabVirDir | Out-File .\results$date\CAS\$($cAServer.name)VirDir.txt -Append
    "Outlook Web Acess Virtual Directory", $oWAVirDir | Out-File .\results$date\CAS\$($cAServer.name)VirDir.txt -Append
    "Exchange Web Services Virtual Directory", $eWSVirDir | Out-File .\results$date\CAS\$($cAServer.name)VirDir.txt -Append
    "Outlook Anywhere Virtual Directory", $outlookAnywhereVirDir | Out-File .\results$date\CAS\$($cAServer.name)VirDir.txt -Append

    #Writing Event Logs

    $eventLogs = Get-EventLog -LogName Application -ComputerName $cAServer.Name -Source MSExchange*
    $eventLogs | Export-Csv -Path .\results$date\CAS\$($cAServer.name)eventlog.csv

}

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-E15OrganizationInfo {
    Param(
        [string]$date
    )

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

    #Collecting Org Data
    $owaMailPol = Get-OwaMailboxPolicy
    $activeSyncMailPol = Get-MobileDeviceMailboxPolicy
    $addressPol = Get-AddressBookPolicy
    $emailPol = Get-EmailAddressPolicy
    $malFiltPol = Get-MalwareFilterPolicy
    $tipPol = Get-PolicyTipConfig
    $retenPol = Get-RetentionPolicy
    $retenPolTag = Get-RetentionPolicyTag
    $sharePol = Get-SharingPolicy
    $uMMailPol = Get-UMMailboxPolicy
    $mailboxes = Get-Mailbox -ResultSize Unlimited
    $mailboxSize += ($mailboxes | Get-MailboxStatistics).TotalItemSize.Value
    $mailboxSize | % { $totalSize = $totalSize + $_ }
    $actSyncDev = $mailbox | Get-MobileDevice
    $dagConfig = Get-DatabaseAvailabilityGroup 
    $dagInfo = Get-DatabaseAvailabilityGroupConfiguration
    $pubFoldDB = Get-PublicFolderDatabase
    $pubFolder = Get-PublicFolder -GetChildren


    #Writing Org info

    "OWA Mailbox Policy", $owaMailPol | Out-File .\results$date\OrgConfig\Policy.txt
    "ActiveSync Device Policy", $activeSyncMailPol | Out-File .\results$date\OrgConfig\Policy.txt -Append
    "Address Book Policy", $addressPol | Out-File .\results$date\OrgConfig\Policy.txt -Append
    "Email Address Polict", $emailPol | Out-File .\results$date\OrgConfig\Policy.txt -Append
    "Malware Filter Policy", $mailFiltPol | Out-File .\results$date\OrgConfig\Policy.txt -Append
    "Policy Tip Config", $tipPol | Out-File .\results$date\OrgConfig\Policy.txt -Append
    "Retention Policy", $retenPol | Out-File .\results$date\OrgConfig\Policy.txt -Append
    "Retention Policy Tags", $retenPolTag | Out-File .\results$date\OrgConfig\Policy.txt -Append
    "Sharing Policy", $sharePol | Out-File .\results$date\OrgConfig\Policy.txt -Append
    "UM Mailbox Policy", $uMMailPol | Out-File .\results$date\OrgConfig\Policy.txt -Append

    #All Org appliances

    $mailboxes | Export-Csv -Path .\results$date\OrgConfig\AllMailboxes.csv
    "Total size of all Mailboxes", $totalSize | Out-File .\results$date\OrgConfig\OtherAttributes.txt
    "Database Availability Group Info", $dagConfig | Out-File .\results$date\OrgConfig\DAG.txt
    "Database Availability Group Config", $dagInfo | Out-File .\results$date\OrgConfig\DAG.txt -Append
    "Public Folder Database", $pubFoldDB | Out-File .\results$date\OrgConfig\PublicFolder.txt
    "Public Folders", $pubFolder | Out-File .\results$date\OrgConfig\Publicfolder.txt -Append

}
Expand

As a side note, I’m going to be attending a Lync Enterprise Voice conference today, so hopefully I learn some new good PowerShell to bring to from this as well!

Talk to you guys soon!

Leave a Reply

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