PowerShell/Microsoft/PingCheck.ps1

47 lines
1.5 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### PowerShell Script, written by Arne.thiel[at]avast.com, 07.02.2018
### influenced by https://www.windowspro.de/script/test-connection-ping-powershell-senden
###https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-connection?view=powershell-6
# Variablen Deklarieren welche via Managed Workplace abgefragt werden
Param(
[string]$DestinationIP1
)
## Anlegen einer Funktion Pingcheck
Function Pingcheck
{
$objres = Test-Connection -ComputerName $DestinationIP1 -Count 6 -Quiet
if($objres -eq $false){Write-Host "Host $DestinationIP1 nicht ereichbar!"}
ElseIf ($objres -eq $true) {Write-Host "Host $DestinationIP1 ereichbar!"}
# Prüfen on die Ereignisanzeigen Quelle Managed Workplace Eventlog bereits existiert, falls nicht, wird diese erzeugt
if (!(Get-EventLog -LogName "Application" -Source "Managed Workplace”)){
New-EventLog LogName Application Source “Managed Workplace”
}
## Erzeugen von Abfrage ob Zielgerät verfügbar ist und schreiben der Ereignisanzeige
if ($objres -eq $true)
{Write-EventLog LogName Application Source “Managed Workplace” EntryType Information EventID 15 Message “System: $DestinationIP1 erreichbar: Test-Connection $res"}
else {Write-EventLog LogName Application Source Managed Workplace EntryType Warning EventID 155 Message "System: $DestinationIP1 nicht erreichbar: Test-Connection $res"}
}
## Ausführen der oben angelegten Funktion:
pingcheck ($DestinationIP1)