powershell - 在服务器无法访问后调用 WebRequest 工作

标签 powershell monitoring scom

我在 SCOM PowerShell 脚本中使用 Invoke-WebRequest 定期监控 URI 的可用性。我的脚本相当简单(因为我对 PS 知之甚少:-)):

$scomapi = new-object -comObject "MOM.ScriptAPI"
$scompb = $scomapi.CreatePropertyBag()
$fullHostName = "https://" + <full path to monitored web endpoint>
$result = Invoke-WebRequest $fullHostName
if($result.content) {
    $scompb.AddValue("ConfigurationReachable",$true);
} else {
    $scompb.AddValue("ConfigurationReachable",$false);
}           
$scomapi.AddItem($scompb) 
$scomapi.ReturnItems()

为了测试这个脚本,我在运行我想进行监控的 SCOM 代理的客户端上的 hosts 文件中进行了手动更改。有趣的是,即使主机无法访问(通过从该机器执行 ping 测试),该脚本仍能成功获取 Web 端点。

我直接从命令行做了一些进一步的测试,没有任何变化。即使我没有 ping 到远程地址,Invoke-WebRequest 仍然成功并获取网页。那么我在这里做错了什么?

最佳答案

我知道这是旧的,但以防万一这对某人有帮助:

我遇到了类似的问题,添加“-Disable KeepAlive”为我解决了这个问题。

关于powershell - 在服务器无法访问后调用 WebRequest 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18556456/

相关文章:

powershell - 如何处理不同的路径分隔符?

powershell - 更改$ null行为以打印出来?

amazon-web-services - 如何在 EBS 实例空间不足时收到警报?

powershell - Microsoft SCOM 中的 Get-SCOMMonitoringObject 和 get-scomclassinstance 有什么区别?

mysql - 我可以集成 mysql 和 sql server 数据库以在 sql server 上查看它们吗

regex - 在 PowerShell 字符串中的 32 个字符 + 空格后返回新行

java - 当 URL 相同时,如何区分 New relic 中的 GET 和 PUT 请求事务?

linux - 无法为 nagios 配置远程 nrpe 插件

linux - 如何找到Linux节点的SCOM管理组

powershell - 调用MailMerge.OpenDataSource()设置连接