我有一个Powershell脚本可以从本地服务器获取另一个PS脚本并运行PS脚本
当服务器不可用时,网络中的所有系统都会给出“通用故障”错误,或者一个错误异常带有“1”参数的调用“DownloadString”“远程服务器返回错误:(404)未找到。”
start-sleep 120
$i=0
While ($true) {
if ($StatusCode = Test-Connection -ComputerName 192.168.1.1 -Quiet) {
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('http://192.168.1.2/service/ok.ps1'))
Break
}
}
friend ,当服务器不可用或内部网络上的系统不可用时,该怎么办?此消息没有出现此错误,请等待系统访问本地网络或服务器?谢谢
问候
最佳答案
如果服务器在线,请首先ping到chck,如果服务器答复则继续。但是您要ping 192.168.1.1,但是要从192.168.1.2下载文件,因此必须ping 192.168.1.2。还要在测试连接中将ErrorAction设置为SilentlyContinue
start-sleep 120
$i=0
While ($true) {
if (Test-Connection -ComputerName 192.168.1.2 -Quiet -ErrorAction SilentlyContinue) {
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('http://192.168.1.2/service/ok.ps1'))
Break
}
Else {
"Generic Failure"
}
当您收到404错误时,服务器上不存在请求的文件。检查URL。如果URL有效,则文件可能已被移动,重命名或删除。服务器似乎在本地网络中,因此请与服务器管理员联系。
关于windows - Powershell脚本中的通用故障错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63096230/