0

变量 $reperr 没有在此处的双引号字符串内扩展。当脚本块完成时,$reperr 确实有一个值,但它不会在此处的字符串中打印,我在正文中得到的只是纯文本“domain.com AD 复制当前存在错误。”

Clear-Variable -name "reperr"
$reperr = Get-ADReplicationPartnerMetadata -target * |? {$_.ConsecutiveReplicationFailures -eq "0"} |select Server, ConsecutiveReplicationFailures
$smtpserver = "10.25.172.2"
#$recipients = "email@emailaddy.com"
$recipients = "user@doamin.com"
$sender = "ad_repl_status@domain.com"
$subject = "DOMAIN.COM ACTIVE DIRECTORY REPLICATION ISSUES DETECTED!"
$body = @"
There are currently errors with domain.com AD replication.
$reperr
"@
 if (!$reperr)
  {
   Write-Host "AD REPLICATION IS CLEAN"
  }
 else
  {
   Send-MailMessage -Priority High -SmtpServer $smtpserver -From $sender -To $recipients -Subject $subject -Body $body  
  }
4

0 回答 0