Powershell代码Telnet网站或ping网站如果没有连接Works重启iis

时间:2018-04-28 14:32:04

标签: powershell

请帮助 我有一个服务器赢得2012年

我有一个网站www.forme.com.ph

我有时会停止iis

我想要代码Powershell

执行以下操作

Telnet网站或ping网站。

如果有连接则无效。

如果没有连接,请重新启动iis

1 个答案:

答案 0 :(得分:1)

测试你是否可以" ping"一个网站:

#basic test to see if you can connect to the port
$tcp = [System.Net.Sockets.TcpClient]::new()
try {
    $tcp.Connect('example.com', 443) 
    $tcp.Dispose()
} catch {
    #put code to restart IIS here
}

或者:

#more thorough test to see if you can get a response from the web server
try {
    $response = Invoke-WebRequest -Uri 'https://example.com' -UseBasicParsing -Method Head
} catch {
    #put code to restart IIS here
}

重新启动IIS:

& {iisreset}