In my job I try to make the process as efficient as possible so that I can determine the issue quickly and then resolve it as quickly as possible. I was having issue with the Test-Mailflow cmdlet and running it remotely against the servers. I was getting the following error:
MapiExceptionSendAsDenied: Unable to submit message. (hr=0x80070005, ec=1244)
If I had multiple servers to test, I would have to logon to each server and run the test which is not efficient at all. I wanted to automate it more without having to change permissions to do so. I wanted to run an Invoke-Command and place the PSSession for Exchange in that command so that I could run the Test-Mailflow cmdlet and get the results.
Paul Cunningham wrote a great article and script to resolve this. READ HERE
His script allows you to input the server name when running the PS1 from the PowerShell Command Prompt:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | [CmdletBinding()] param ( [Parameter( Mandatory=$false)] [string]$Server ) Write-Verbose "Creating PSSession for $server" try { $url = (Get-PowerShellVirtualDirectory -Server $server | Where {$_.Name -eq "Powershell (Default Web Site)"}).InternalURL.AbsoluteUri $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $url -ErrorAction STOP } catch { Write-Verbose "Something went wrong" Write-Warning $_.Exception.Message EXIT } try { Write-Verbose "Running mail flow test on $Server" $result = Invoke-Command -Session $session {Test-Mailflow} -ErrorAction STOP $testresult = $result.TestMailflowResult } catch { Write-Verbose "An error occurred" Write-Warning $_.Exception.Message EXIT } Write-Host "Mail flow test: $testresult" -foregroundcolor Yellow Write-Verbose "Removing PSSession" Remove-PSSession $session.Id |
I was able to take the Test-MailflowRemote.ps1 script and set it to run on all the mailbox servers for the environment I was monitoring. Now, we can only run the Test-MailFlow cmdlet against Exchange Mailbox Servers that have active databases mounted on them. So, I run the following first to get the list of Mailbox Servers that contain at least 1 active database:
1 | $Svrs = get-mailboxserver * | Get-MailboxDatabaseCopyStatus | ? {$_.Status -eq "Mounted"} | Group-Object ActiveDatabaseCopy | Sort-Object Name | Select-Object Name |
I then run the ps1 script using the array I created with the $Svrs variable:
1 | foreach ($Svr in $Svrs) { $Svr.Name ; C:\PSScripts\TestMailFlowRemote.ps1 $Svr.Name } |
Output:
1 2 3 4 5 6 | EXMBX01 Mail flow test: Success EXMBX02 Mail flow test: Success EXMBX03 Mail flow test: Success |
This helps a bunch when you need to run on multiple servers and get the test information quickly. Please comment! Happy Troubleshooting!
Yeah, but this way it only tests if the server can send a mail to itself. How do you test that the system mailbox on all Mailbox servers can successfully send a message to the system mailbox on all other Mailbox servers?