{"id":122,"date":"2019-01-11T04:35:39","date_gmt":"2019-01-11T09:35:39","guid":{"rendered":"http:\/\/itblog.ldlnet.net\/?p=122"},"modified":"2019-01-29T19:54:51","modified_gmt":"2019-01-30T00:54:51","slug":"running-test-mailflow-on-remote-exchange-servers","status":"publish","type":"post","link":"https:\/\/itblog.ldlnet.net\/index.php\/2019\/01\/11\/running-test-mailflow-on-remote-exchange-servers\/","title":{"rendered":"Running Test-MailFlow on remote Exchange Servers"},"content":{"rendered":"\n<p>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:<\/p>\n\n\n\n<p class=\"has-text-color has-small-font-size has-medium-pink-color\">MapiExceptionSendAsDenied: Unable to submit message. (hr=0x80070005, ec=1244)<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p class=\"has-small-font-size\">Paul Cunningham wrote a great article and script to resolve this.<strong> <\/strong><a rel=\"noreferrer noopener\" aria-label=\"READ HERE (opens in a new tab)\" href=\"https:\/\/practical365.com\/exchange-server\/exchange-2013-test-mailflow-error-for-remote-mailbox-servers\/\" target=\"_blank\"><strong>READ HERE<\/strong><\/a><\/p>\n\n\n\n<p>His script allows you to input the server name when running the PS1 from the PowerShell Command Prompt:<\/p>\n\n\n<pre class=\"lang:PowerShell\" title=\"Test-MailflowRemote.ps1\">[CmdletBinding()]\nparam (\n[Parameter( Mandatory=$false)]\n[string]$Server\n)\n\u00a0\nWrite-Verbose \"Creating PSSession for $server\"\ntry\n{\n\u00a0\u00a0\u00a0\u00a0$url = (Get-PowerShellVirtualDirectory -Server $server | Where {$_.Name -eq \"Powershell (Default Web Site)\"}).InternalURL.AbsoluteUri\n\u00a0\u00a0\u00a0\u00a0$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $url -ErrorAction STOP\n}\ncatch\n{\n\u00a0\u00a0\u00a0\u00a0Write-Verbose \"Something went wrong\"\n\u00a0\u00a0\u00a0\u00a0Write-Warning $_.Exception.Message\n\u00a0\u00a0\u00a0\u00a0EXIT\n}\n\u00a0\ntry\n{\n\u00a0\u00a0\u00a0\u00a0Write-Verbose \"Running mail flow test on $Server\"\n\u00a0\u00a0\u00a0\u00a0$result = Invoke-Command -Session $session {Test-Mailflow} -ErrorAction STOP\n\u00a0\u00a0\u00a0\u00a0$testresult = $result.TestMailflowResult\n\u00a0\n}\ncatch\n{\n\u00a0\u00a0\u00a0\u00a0Write-Verbose \"An error occurred\"\n\u00a0\u00a0\u00a0\u00a0Write-Warning $_.Exception.Message\n\u00a0\u00a0\u00a0\u00a0EXIT\n}\n\u00a0\nWrite-Host \"Mail flow test: $testresult\" -foregroundcolor Yellow\nWrite-Verbose \"Removing PSSession\"\nRemove-PSSession $session.Id<\/pre>\n\n\n\n<p>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:<\/p>\n\n\n<pre class=\"lang:PowerShell\" title=\"Get Mailbox Server List with at least one active database\">$Svrs = get-mailboxserver * | Get-MailboxDatabaseCopyStatus | ? {$_.Status -eq \"Mounted\"} | Group-Object ActiveDatabaseCopy | Sort-Object Name | Select-Object Name<\/pre>\n\n\n\n<p>I then run the ps1 script using the array I created with the $Svrs variable:<\/p>\n\n\n<pre class=\"lang:PowerShell\" title=\"Run TestMailflowRemote.ps1 against variable array\">foreach ($Svr in $Svrs) { $Svr.Name ; C:\\PSScripts\\TestMailFlowRemote.ps1 $Svr.Name }<\/pre>\n\n\n\n<p class=\"has-small-font-size\"><strong>Output:<\/strong><\/p>\n\n\n<pre class=\"lang:PowerShell nums:false\" title=\"Script Output\">EXMBX01\nMail flow test: Success\nEXMBX02\nMail flow test: Success\nEXMBX03\nMail flow test: Success<\/pre>\n\n\n\n<p>This helps a bunch when you need to run on multiple servers and get the test information quickly. Please comment! Happy Troubleshooting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my job I try to make the process as efficient as possible so that I can determine the issue quickly and<\/p>\n<p class=\"link-more\"><a class=\"myButt \" href=\"https:\/\/itblog.ldlnet.net\/index.php\/2019\/01\/11\/running-test-mailflow-on-remote-exchange-servers\/\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":161,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[15,9,8,13],"class_list":["post-122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-exchange","category-powershell","tag-cmdlet","tag-exchange","tag-powershell","tag-script","odd"],"_links":{"self":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":3,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":184,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/122\/revisions\/184"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media\/161"}],"wp:attachment":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}