PowerShell Monitor, restart NIC

Source: Internet
Author: User

#powershell Monitoring, restart the network card

A Windows server, due to a large load, occasionally network interruption, wrote a PowerShell script, monitoring IP is not through, restart the network card

Cls$host. Ui. Rawui.windowtitle=' ... VM monitoring ... ' $host. Ui. Rawui.foregroundcolor=' Green '#version V1.3.9#t1间隔时间s $t 1=5$log=' C:\Router.log.txt '#region $nu=0$n 1="##########"$n 2="Total number of monitors"$CQ 1=0$CQ 2=0$ip 1=' 192.168.0.1 '$ip 2=' 172.16.11.145 '$ip 3=' 172.16.11.8 '#endregionif(Test-path $log) {}Else    {    "Initialize log"echo $n 1>$log echo $n 2>>$log Echo $nu>>$log echo $n 1>>$log} while(1-lt 2) {Sleep $t 1 CLS $log 1=get-Content $log $nu= $log 1[2] $nu=[int] $nu + 1#print echo $n 1 echo"$ ($n 2): $ ($nu)"Echo"Monitoring interval: $ ($t 1) S"Echo"Restart Nic: $ ($CQ 1)"Echo"Restart Route: $ ($cq 2)"echo $n 1 #write echo $n 1>$log echo $n 2>>$log Echo $nu>>$log echo $log 1[3. ($log 1.count-1)] >>$log #checkif((get-wmiobject-query"SELECT * from win32_pingstatus WHERE Address = ' $ip 1 '"). Statuscode-eq 0)    {        "The router is online!"#检测内网if((get-wmiobject-query"SELECT * from win32_pingstatus WHERE Address = ' $ip 2 '"). Statuscode-eq 0)            {  "The Lan is online!"} elseif (Get-wmiobject-query"SELECT * from win32_pingstatus WHERE Address = ' $ip 3 '"). Statuscode-eq 0)            {  "The Lan is online!" }            Else            {            "Restart intranet network card"$CQ 1= $cq 1 + 1Echo"Restart intranet NIC, $ (get-date-format ' yyyy-mm-dd HH:mm:ss.ffff ')">>$log Get-netadapter-name' Local connection '| restart-Netadapter Get-netadapter-name' Lan '| restart-Netadapter Sleep30            }    }    Else    {      "The router is offline!"     "Restart routing nic"$CQ 1= $cq 1 + 1Echo"Restart routing nic, $ (get-date-format ' yyyy-mm-dd HH:mm:ss.ffff ')">>$log Get-netadapter-name' Wan2 '| restart-Netadapter Get-netadapter-name' Lan2 '| restart-Netadapter Sleep30#再次检测if((get-wmiobject-query"SELECT * from win32_pingstatus WHERE Address = ' $ip 1 '"). Statuscode-eq 0)         { "The route is online!" }         Else         {        "Restart Router"$CQ 2= $CQ 2 + 1Echo"Restart router, $ (get-date-format ' yyyy-mm-dd HH:mm:ss.ffff ')">>$log $vname=' Ikuai-router 'Restart-VM $vname-Force Sleep100         }    }}?

PowerShell Monitor, restart NIC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.