Ping via powershell fejler efter 30-60 minutter
Jeg har forsøgt at lave et script som pinger en server indtil der ikke er svar fra den mere, men efter 30-60 minutter fejler scriptet pludseligt. Jeg kan ikke lige regne ud hvorfor.Fejl:
The term 'pingServer' is not recognized as the name of a cmdle
t, function, script file, or operable program. Check the spell
ing of the name, or if a path was included, verify that the pa
th is correct and try again.
At C:\Documents and Settings\itsjan\Local Settings\Temp\aa3b45
d9-7915-47dc-bd17-03d9e3e824f6.ps1:6 char:11
+ pingServer <<<<
+ CategoryInfo : ObjectNotFound: (pingServer:Str
ing) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Script:
function pingServer{
$serverIP = test-connection -ComputerName $servername -Quiet
repeat
}
function repeat{
if($serverIP -match "true"){
pingServer
}
else{
trap [Exception]{
write-host
write-error $("TRAPPED: " + $_.Exception.GetType().FullName);
write-error $("TRAPPED: " + $_.Exception.Message);
pingAlarm
}
}
}
function pingAlarm{
for ( $i = 1; $i -le 1; $i+=1 ) {
Start-Process c:\alarm\ding.wav
Start-Sleep -Seconds 1
}
$b = new-object -comobject wscript.shell
$b.popup("Der er ikke forbindelse til serveren",0)
}
pingServer