# Importieren der notwendigen .NET-Namespaces Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Windows.Forms # Erstellen des Hauptfensters $window = New-Object System.Windows.Window $window.Title = "Ping Monitor" $window.Width = 600 $window.Height = 400 # Erstellen des DataGrid $dataGrid = New-Object System.Windows.Controls.DataGrid $dataGrid.Margin = "10" $dataGrid.AutoGenerateColumns = $false $dataGrid.IsReadOnly = $true # Definieren der Spalten für das DataGrid $hostColumn = New-Object System.Windows.Controls.DataGridTextColumn $hostColumn.Header = "Host" $hostColumn.Binding = New-Object System.Windows.Data.Binding "TargetHost" $dataGrid.Columns.Add($hostColumn) $statusColumn = New-Object System.Windows.Controls.DataGridTextColumn $statusColumn.Header = "Status" $statusColumn.Binding = New-Object System.Windows.Data.Binding "Status" $dataGrid.Columns.Add($statusColumn) $roundtripColumn = New-Object System.Windows.Controls.DataGridTextColumn $roundtripColumn.Header = "Roundtrip Time" $roundtripColumn.Binding = New-Object System.Windows.Data.Binding "RoundtripTime" $dataGrid.Columns.Add($roundtripColumn) $timestampColumn = New-Object System.Windows.Controls.DataGridTextColumn $timestampColumn.Header = "Timestamp" $timestampColumn.Binding = New-Object System.Windows.Data.Binding "Timestamp" $dataGrid.Columns.Add($timestampColumn) # Hosts, die gepingt werden sollen $hosts = @("ME0001", "ME0002", "8.8.8.8", "1.1.1.1") # Freigegebene ObservableCollection für die Ping-Ergebnisse $pingResults = New-Object System.Collections.ObjectModel.ObservableCollection[PSCustomObject] # Funktion zum Durchführen des Pings # Importieren der notwendigen .NET-Namespaces Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Windows.Forms # Erstellen des Hauptfensters $window = New-Object System.Windows.Window $window.Title = "Ping Monitor" $window.Width = 600 $window.Height = 400 # Erstellen des DataGrid $dataGrid = New-Object System.Windows.Controls.DataGrid $dataGrid.Margin = "10" $dataGrid.AutoGenerateColumns = $false $dataGrid.IsReadOnly = $true # Definieren der Spalten für das DataGrid $hostColumn = New-Object System.Windows.Controls.DataGridTextColumn $hostColumn.Header = "Host" $hostColumn.Binding = New-Object System.Windows.Data.Binding "TargetHost" $dataGrid.Columns.Add($hostColumn) $statusColumn = New-Object System.Windows.Controls.DataGridTextColumn $statusColumn.Header = "Status" $statusColumn.Binding = New-Object System.Windows.Data.Binding "Status" $dataGrid.Columns.Add($statusColumn) $roundtripColumn = New-Object System.Windows.Controls.DataGridTextColumn $roundtripColumn.Header = "Roundtrip Time" $roundtripColumn.Binding = New-Object System.Windows.Data.Binding "RoundtripTime" $dataGrid.Columns.Add($roundtripColumn) $timestampColumn = New-Object System.Windows.Controls.DataGridTextColumn $timestampColumn.Header = "Timestamp" $timestampColumn.Binding = New-Object System.Windows.Data.Binding "Timestamp" $dataGrid.Columns.Add($timestampColumn) # Hosts, die gepingt werden sollen $hosts = @("ME0002", "ME0001", "8.8.8.8", "1.1.1.1") # Freigegebene ObservableCollection für die Ping-Ergebnisse $pingResults = New-Object System.Collections.ObjectModel.ObservableCollection[PSCustomObject] # Funktion zum Durchführen des Pings function Start-PingMonitor { param ( [string[]]$hosts, [System.Collections.ObjectModel.ObservableCollection[PSCustomObject]]$results ) foreach ($targetHost in $hosts) { try { $ping = New-Object System.Net.NetworkInformation.Ping $reply = $ping.Send($targetHost) $pingResult = [PSCustomObject]@{ TargetHost = $targetHost Status = if ($reply.Status -eq "Success") { "Success" } else { "Failed" } RoundtripTime = $reply.RoundtripTime Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" } # Hinzufügen des Ergebnisses zur freigegebenen ObservableCollection $results.Add($pingResult) } catch { $pingResult = [PSCustomObject]@{ TargetHost = $targetHost Status = "Error" RoundtripTime = "N/A" Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" } # Hinzufügen des Fehler-Ergebnisses zur freigegebenen ObservableCollection $results.Add($pingResult) } } } # Erstellen des DispatcherTimer $timer = New-Object System.Windows.Threading.DispatcherTimer $timer.Interval = [System.TimeSpan]::FromSeconds(1) $timer.Add_Tick({ Start-PingMonitor -hosts $hosts -results $pingResults }) # Hinzufügen des DataGrid zum Fenster $window.Content = $dataGrid # Setzen der ItemsSource des DataGrid auf die ObservableCollection $dataGrid.ItemsSource = $pingResults # Starten des Timers $timer.Start() # Anzeigen des Fensters $window.ShowDialog() | Out-Null # Beenden des Timers, wenn das Fenster geschlossen wird $timer.Stop()