namerg
asked on
Not able to send values in the Body of email
Hello, i have the following code
It should bring the values from $ResolveDNS in the body of the email. Thoughts...?
Thanks for your help,
$SiteName = "ds-app.domain.co"
$SiteIP = "10.101.35.116"
$ResolveDNS = Resolve-DnsName ds-app.domain.com -DnsOnly
if (($ResolveDNS.Name -eq $SiteName) -And ($ResolveDNS.IPAddress -eq $SiteIP))
{
Exit
#Write-host "All is good"
}
Else {
$enablemail = @()
$enablemail = "yes"
$smtpServer = "SMTPServer.corp.lcl"
$mailfrom = "ResolveDNS@domain.lcl"
$mailto = "user@domain.com"
$replyto = "sysadmins@domain.com"
#$mailTo = "URGENT@domain.com"
if ($enablemail -match "yes")
{
$msg = New-Object Net.Mail.MailMessage
$smtp = New-Object Net.Mail.smtpClient($smtpServer)
$msg.From = $mailfrom
$msg.To.Add($mailto)
$msg.ReplyTo = $replyto
$msg.Subject = "Site: $SiteName Not Resolvable"
$msg.Body = "Site: $SiteName Not Resolvable`nName: ($ResolveDNS).Name, TTL: ($ResolveDNS).TTL, IP Address: ($ResolveDNS).IPAddress"
$smtp.Send($msg)
}
}
But when i get the email, the body looks like the following:Site: ds-app.domain.co Not Resolvable
Name: (Microsoft.DnsClient.Commands.DnsRecord_A).Name, TTL: (Microsoft.DnsClient.Commands.DnsRecord_A).TTL, IP Address: (Microsoft.DnsClient.Commands.DnsRecord_A).IPAddress
It should bring the values from $ResolveDNS in the body of the email. Thoughts...?
Thanks for your help,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER