我在为Windows 10制作脚本时遇到一些麻烦,它会每2分钟检查一次我的互联网连接,如果找不到任何连接则重新启动计算机。
我尝试使用PowerShell:
mainLoop()
sleep 120
{
if (!(Test-Connection 8.8.8.8 -Quiet)) {
#Write-Host "Not connected"
Restart-Computer
} else {
mainLoop()
}
}
你有什么建议让它有效吗?
答案 0 :(得分:3)
在远程主机可访问时循环,并在循环终止后重新启动:
foreach ( $manager_add_new_room_type_desc as $key => $room_type ) :
$renters = $manager_add_new_room_rented_to[$room_type];
$rented_to = array();
foreach ($renters['userid'] as $index => $userid) :
$rented_to[] = array('userid' => $userid, 'from' => $renters['from'][$index], 'to' => $renters['to'][$index]);
endforeach;
$add_new_room_information[$room_type] = array(
'm2' => $manager_add_new_room_type_m2[$key],
'price' => $manager_add_new_room_type_rent_price[$key],
'rooms' => $manager_add_new_room_type_rooms[$key],
'extra' => $manager_add_new_room_type_extra[$key],
'rented_to' => $rented_to
)
);
endforeach;