Exchange DAG Power Shell SMTP Email Settings Help needed

Exchange 2016 CU10 DAG 2 Nodes
Windows 2016 Data Center  Windows 2012 R2
VMWare ESXI 6.5

Setup power shell scripts to email me with system status also have applications like SQL that send email also.

Problem is when Node 1 is down for maint work the email do not flow .

How do I get email to work in my powershell scripts ?


$Server = hostname 
$Subject = "$Server DFS State Report"
$Body = "Open attachment for DFS State Report"
$From = "no-reply@mynet.com"
$To = "systems-alert@mynet.com"
$LogFolder = "c:\util\logs"
$LogFile = "dfsstate.txt"

remove-item -path $LogFolder\$LogFile -Force 

cmd /c 'wmic /namespace:\\root\microsoftdfs path dfsrreplicatedfolderinfo get replicationgroupname, replicatedfoldername, state' >$LogFolder\$LogFile

$PSEmailServer = "SERV021-N1.MYNET.COM"
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -smtpserver $PSEmailServer -attachment "$LogFolder\$LogFile"

Open in new window





NODE 2 is SERV021-N2.MYNET.COM

Any suggestions.

THanks

Tom
LVL 23
Thomas GrassiSystems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MichelangeloConsultantCommented:
You are using a specific node to send emails. Can you use the public name? If not, implement a
If (test-connection servername1 -port 25 ) { $smtprelay = servername } else { $smtprelay = servername2 }

That should allow to use the currently available server.
 Or

try {
    Send-MailMessage servername1  -EA Stop;

    }
catch { Write-Host $_
    Sleep 1
    Send-MailMessage servername2
      }


It's a hack, really.  By using a proper balancer you can achieve fault tolerance but that may be impratical to implement in case the client is on the same network of the servers
0
Thomas GrassiSystems AdministratorAuthor Commented:
Michaelangelo

using DNS Round Robin

All Hosts and internal client on same network

How do I determine my external address?
0
MichelangeloConsultantCommented:
Round robin does not provide fault tolerance so no way.
You have to manage the error in your script.
0
Webinar: Miercom Evaluates Wi-Fi Security

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom how WatchGuard's Wi-Fi security stacks up against the competition in our upcoming webinar!

Thomas GrassiSystems AdministratorAuthor Commented:
I found this command test-netconnection -computername SERV021-N1 -port 25

The test-connection serv021-n1 -port 25 did not work
0
timgreen7077Exchange EngineerCommented:
Do you have a relay receive connector for accepting emails from apps, printers or servers on both of your exchange servers or just on 1 of them?
0
Thomas GrassiSystems AdministratorAuthor Commented:
Tim

I have a relay receive connector on both Nodes
0
MichelangeloConsultantCommented:
@thomas yes i'writing from memory, commands syntax may be imprecise.
Also pay attention at what Timgreen wrote, i assumed you have the same configuration on both your exchange as it is a Dag in which you usually repliacate receive connectors. If not, create the same connector in the other node to allow the midified script to work.
0
timgreen7077Exchange EngineerCommented:
Is "SERV021-N1.MYNET.COM" server1 (currently down for maint) or is it server2?
0
timgreen7077Exchange EngineerCommented:
This part of your script"

$PSEmailServer = "SERV021-N1.MYNET.COM"

Needs to be changed to Server2, and make sure that that IP address of the sender server is added to the relay connector on server2 if its not there already.
0
Thomas GrassiSystems AdministratorAuthor Commented:
Guys

Both nodes are currently up I was applying CU 10 on NODE 1 today

I came up with the following code which will work for the power shell scripts but not for the APPs etc.


$Mailservers = @("SERV021-N1.mynet.com","SERV021-N2.mynet.com")
if (Test-NetConnection -ComputerName $Mailservers[0] -Port 25 -InformationLevel Quiet) {
    $PSEmailServer = $Mailservers[0]
    Write-Host $PSEmailServer is UP
    Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -smtpserver $PSEmailServer -attachment "$LogFolder\$LogFile"
}
elseif (Test-NetConnection -ComputerName $Mailservers[1] -Port 25 -InformationLevel Quiet) {
    $PSEmailServer = $Mailservers[1]
    Write-Host $PSEmailServer is UP
    Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -smtpserver $PSEmailServer -attachment "$LogFolder\$LogFile"
 } else {
    Write-Error "No Mailservers Available"
 }

Open in new window

0
MichelangeloConsultantCommented:
That looks good if emails go through. What is APPs ? Other applications? If so yes, they won't work unless you manually change the smtp server they use  when the configured one is in maintenance.
0
Thomas GrassiSystems AdministratorAuthor Commented:
Hello

I am not sure if the script I wrote will work by checking port 25.  Not sure when you place Exchange into Maint mode the port will not respond.

So I created this small script on my exchange servers

Add-PSSnapin microsoft.exchange.management.powershell.SnapIn;

Get-servercomponentstate -identity SERV021-N1 -Component hubtransport

Open in new window


I know that the hubtransport component is inactive durning the upgrade

That returns what I need

My problem is how can I invoke that script remotely from each server?

I tried this

Invoke-Command -ComputerName $Mailservers[0] -FilePath c:\Util\get-exchangestatus.ps1 

Open in new window



It fails with can not find get-exchangestatus.ps1  

Thoughts?
0
timgreen7077Exchange EngineerCommented:
Thomas, this is an ever changing question and solutions. I would suggest the following only if your original script works.
If it works do the following:

In your on-prem DNS create 2 A records and point them to each of your 2016 exchange servers:
Give the A records a host name of something like "internalrelay.domain.com", and point them to server1 and create another with the same host name and point to server2.

You mentioned that both servers have receive connector you created that is used for apps, servers and so forth, so on both of those connector do the following:

Double click the connector > scope > under FQDN enter the name of the A record you created (internalrelay.domain.com) and save it.

Use this name instead of the actual server name when you need an app, printer, or server to email. This will keep you from needing to change the server name on your script.

On your script change the following $PSEmailServer = "SERV021-N1.MYNET.COM" to $PSEmailServer = "internalrelay.domain.com"

Now when you will be putting a server in maint mode for extended time, go into DNS and delete that A record, that way the servers will only print to the server that is currently up, and once you are done with the maint, just add the A record back.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thomas GrassiSystems AdministratorAuthor Commented:
Tim

I was thinking of the same thing in DNS.

I created two DNS records.

Tested and it worked

I still would like to get the script to work by testing the componentstatus
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.