相关疑难解决方法(0)

用于监控状态和发送电子邮件结果的Powershell脚本

我有很多网站来监控他们的上/下状态,可能的错误,ping以及我通过脚本获得的其他事情.我的想法如下:此脚本将与任务计划程序一起运行,获取结果并向我们发送电子邮件(来自SQA出版物).所以,我成功地创建了脚本,他得到了我需要的所有东西并在C:驱动器中生成了一个html文件.我的问题是,在我得到结果后,发送电子邮件的功能不是发送电子邮件.我没有收到任何错误消息,调试很好,SMTP和所有配置都是正确的.但它不会发送附带html文件的电子邮件!

代码是这样的:

$URLListFile = "C:\URLList.txt"  
$URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue 
  $Result = @() 


  Foreach($Uri in $URLList) { 
  $time = try{ 
  $request = $null 

  $result1 = Measure-Command { $request = Invoke-WebRequest -Uri $uri } 
  $result1.TotalMilliSeconds 
  }  
  catch 
  { 

   $request = $_.Exception.Response 
   $time = -1 
  }   
  $result += [PSCustomObject] @{ 
  Time = Get-Date; 
  Uri = $uri; 
  StatusCode = [int] $request.StatusCode; 
  StatusDescription = $request.StatusDescription; 
  ResponseLength = $request.RawContentLength; 
  TimeTaken =  $time;  
  } 

} 

if($result -ne $null) 
{ 
    $Outputreport = "<HTML><TITLE>Website Report Status</TITLE><BODY background-color:peachpuff><font …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-3.0

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1

powershell-3.0 ×1