Jump to content

Edy

Members
  • Gesamte Inhalte

    1
  • Registriert seit

  • Letzter Besuch

Letzte Besucher des Profils

Der "Letzte Profil-Besucher"-Block ist deaktiviert und wird anderen Benutzern nicht angezeit.

Fortschritt von Edy

Newbie

Newbie (1/14)

  • Erste Antwort

Neueste Abzeichen

0

Reputation in der Community

  1. Hallo, ich bin auch ein Anfaenger in PS. Ich versuche ein Skript mit Oberfläche zu erstellen. 1 Oberfläche ist fertig und laut Write-Host bei Selektion auch funktional. 2. Skript für LOG auslesen ist auch fertig und funktioniert. aber die OrdnerVerzeichnis an Skript wir nicht übergeben sondern verwendet den StandartVerzeichnis. Hier mein Skript hoffe um unterstützung. Danke in voraus Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing #Allgemeine Info + groesse $form = New-Object Windows.Forms.Form -Property @{ StartPosition = [Windows.Forms.FormStartPosition]::CenterScreen Size = New-Object Drawing.Size 540, 380 Text = 'Logs durchsuchen' Topmost = $true } #--------------------------------------------------------------------------------- # Labels $Suchtext = New-Object System.Windows.Forms.Label -Property @{ Location = New-Object Drawing.Point 10, 40 Size = New-Object Drawing.Size 110, 20 Text = 'Wonach suchen wir?' } $form.Controls.Add($Suchtext) $SucheIntext = New-Object System.Windows.Forms.Label -Property @{ Location = New-Object Drawing.Point 10, 74 Size = New-Object Drawing.Size 110, 20 Text = 'Suchverlauf' } $form.Controls.Add($SucheIntext) $SpeichernIntext = New-Object System.Windows.Forms.Label -Property @{ Location = New-Object Drawing.Point 10, 95 Size = New-Object Drawing.Size 110, 20 Text = 'Der Speicher Ort' } $form.Controls.Add($SpeichernIntext) #------------------------------------------------------ # Suche Von- Bis $SucheVon = New-Object System.Windows.Forms.Label -Property @{ Location = New-Object Drawing.Point 8, 120 Size = New-Object Drawing.Size 27, 20 Text = 'Von:' } $form.Controls.Add($SucheVon) $SucheBis = New-Object System.Windows.Forms.Label -Property @{ Location = New-Object Drawing.Point 280, 120 Size = New-Object Drawing.Size 25, 20 Text = 'Bis:' } $form.Controls.Add($SucheBis) #--------------------------------------------------------------------------------- # Textbox $textBox = New-Object System.Windows.Forms.TextBox -Property @{ Location = New-Object Drawing.Point 130, 40 Size = New-Object Drawing.Size 255, 20 } $form.Controls.Add($textBox) $textBoxOffnen = New-Object System.Windows.Forms.TextBox -Property @{ Location = New-Object Drawing.Point 120, 69 Size = New-Object Drawing.Size 275, 20 Text = [Environment]::GetFolderPath('Desktop') } $form.Controls.Add($textBoxOffnen) $textBoxSpeicher = New-Object System.Windows.Forms.TextBox -Property @{ Location = New-Object Drawing.Point 120, 90 Size = New-Object Drawing.Size 275, 20 Text = [Environment]::GetFolderPath('Desktop') } $form.Controls.Add($textBoxSpeicher) #--------------------------------------------------------------------------------- # Ok und Cancel button $okButton = New-Object Windows.Forms.Button -Property @{ Location = New-Object Drawing.Point 188, 290 Size = New-Object Drawing.Size 75, 23 Text = 'OK' DialogResult = [Windows.Forms.DialogResult]::OK } $okButton_OnClick = { $OrdnerMitLogs = $textBoxOffnen.Text $PfadTxtDatei = $textBoxSpeicher.Text $NameLogFile = "transaction.log" Write-Host 'OK BUTTON ONCLICK WURDE ausgeführt:' $SpeicherOrdner.FileName Write-Host $textBoxOffnen.Text Write-Host $textBoxSpeicher.Text } #$form.AcceptButton = $okButton $okButton.add_Click($okButton_OnClick) $form.Controls.Add($okButton) $cancelButton = New-Object Windows.Forms.Button -Property @{ Location = New-Object Drawing.Point 263, 290 Size = New-Object Drawing.Size 75, 23 Text = 'Cancel' DialogResult = [Windows.Forms.DialogResult]::Cancel } #$form.CancelButton = $cancelButton $form.Controls.Add($cancelButton) #------------------------------------------------------------------------ # Speicher Button $SpeicherOrtButton = New-Object System.Windows.Forms.Button -Property @{ Location = New-Object Drawing.Point 400, 90 Size = New-Object Drawing.Size 90, 20 Text = 'Speichen unter' } #------------------------------------------------------------------------ $SpeicherOrtButton_OnClick = { Add-Type -AssemblyName System.Windows.Forms $Ausgangsverzeichnis = [Environment]::GetFolderPath('Desktop') $SpeicherOrdner = New-Object System.Windows.Forms.saveFileDialog $SpeicherOrdner.InitialDirectory = $Ausgangsverzeichnis $SpeicherOrdner.FileName = 'test' $SpeicherOrdner.Filter = 'Excel (*.csv)|*.csv' $responseS = $SpeicherOrdner.ShowDialog( ) # $Antwort kann OK oder Cancel sein if ( $responseS -eq [System.Windows.Forms.DialogResult]::OK){ $textBoxSpeicher.Text = $SpeicherOrdner.FileName $Speicher = $SpeicherOrdner.FileName $Speicher.toSting } Write-Host 'Ihr Auswahl Datei:' $SpeicherOrdner.FileName } Write-Host 'Speicher 2' Write-Host $Speicher $SpeicherOrtButton.add_Click($SpeicherOrtButton_OnClick) $form.Controls.Add($SpeicherOrtButton) #------------------------------------------------------------------------ # Suchverlauf Button $SucheInButton = New-Object System.Windows.Forms.Button -Property @{ Location = New-Object Drawing.Point 400, 70 Size = New-Object Drawing.Size 80, 20 Text = 'Suche in' } #------------------------------------------------------------------------ $SucheInButton_OnClick = { Add-Type -AssemblyName System.Windows.Forms $SucheOrdner = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{ RootFolder = 'MyComputer' ShowNewFolderButton = $false } $response = $SucheOrdner.ShowDialog( ) # $Antwort kann OK oder Cancel sein if ( $response -eq [System.Windows.Forms.DialogResult]::OK){ $textBoxOffnen.Text = $SucheOrdner.SelectedPath $OrdnerMitLogs = $SucheOrdner.SelectedPath Write-Host "Es wurde Verzeichnis ausgewaehlt" Write-Host $OrdnerMitLogs } else { $OrdnerMitLogs = $textBoxOffnen.Text Write-Host "Verzeichnis Standart" Write-Host $OrdnerMitLogs } Write-Host 'Ihr Auswahl Datei:' $SucheOrdner.SelectedPath } $SucheInButton.add_Click($SucheInButton_OnClick) $form.Controls.Add($SucheInButton) #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- #Kalender $calendarVon = New-Object Windows.Forms.MonthCalendar -Property @{ Location = New-Object Drawing.Point 38, 120 ShowTodayCircle = $false MaxSelectionCount = 1 } $form.Controls.Add($calendarVon) $calendarBis = New-Object Windows.Forms.MonthCalendar -Property @{ Location = New-Object Drawing.Point 308, 120 ShowTodayCircle = $false MaxSelectionCount = 1 } $form.Controls.Add($calendarBis) #--------------------------------------------------------------------------------- # Datum eingrenzen Von Bis. #Function zum erzeugen eines Arrays, das später bei Suche verwendet wird. function ArrayUntersuchungszeitraum {param([DateTime]$ersterTag,[DateTime]$LetzterTag) $Tage = @() if($LetzterTag -gt $ersterTag){ $start = $ersterTag While ($start -lt $LetzterTag){ $Tage += $start #$start.ToShortDateString() $start = $start.AddDays(1) } $Tage += $LetzterTag } if($ersterTag -gt $LetzterTag){ $start = $LetzterTag While ($start -lt $ersterTag){ $Tage += $start #$start.ToShortDateString() $start = $start.AddDays(1) } $Tage += $ersterTag } return $Tage } # $zeitraum = ArrayUntersuchungszeitraum -ersterTag $DatumVon -LetzterTag $DatumBis #--------------------------------------------------------------------------------------- function SuchOrdner {param([String]$SucheInOrdner) $OrdnerMitLogs = @() If ($textBoxOffnen.Text -gt 'C:\Users\ebbbb\Desktop\Übung PowerShell\Logs Untersuchung'){ $OrdnerMitLogs = $textBoxOffnen.Text } else { $OrdnerMitLogs = $textBoxOffnen.Text } } #------------------------------------------------------------------------ #$PfadTxtDatei = "C:\Temp\test.csv" #$OrdnerMitLogs = $textBoxOffnen.Text # Ist noch fest $NameLogFile = "transaction.log" #--------------------------------------------------------------------------------- # Suchabfolge function LogsAuslesen {param([DateTime]$StartDatum, [DateTime]$EndDatum, [String]$quelle, [String]$Suchkriterium, [String]$dest, [String]$LogName) " " | Out-File $dest -Append "Ergebnis der Suche nach $($Suchbegriff) zwischen dem $($DatumVon.ToShortDateString()) und dem $($DatumBis.ToShortDateString())" | Out-File $dest -Append " " | Out-File $dest -Append " " | Out-File $dest -Append "############################################################################################################################################################################################" | Out-File $dest -Append $UntersuchungsZeitraum = ArrayUntersuchungszeitraum -ersterTag $StartDatum -LetzterTag $EndDatum $UntersuchungsZeitraum = $UntersuchungsZeitraum.ToShortDateString() #$UntersuchungsZeitraum Get-Childitem $quelle | ForEach-Object -process { write-Host $textBoxOffnen.Text $LogFile = Join-Path $quelle -ChildPath $_ $LogFileFinal = Join-Path $LogFile -ChildPath $LogName # Hier definiere ich die Pfad der Log-Datei für einzelne Ordner #Kleiner Einleitungstext " " | Out-File $dest -Append "Es wird untersucht:" | Out-File $dest -Append $_ | Select-Object -ExpandProperty Name | Out-File $dest -Append $LogFileFinal | Out-File $dest -Append #Nun Schaue ich, wie viele Einträg dort sind. $AnzahlEintrage = Get-Content -Path $LogFileFinal | Select-String -Pattern $Suchkriterium | Select-String -Pattern $UntersuchungsZeitraum | Measure-Object | Select-Object -ExpandProperty Count # if Abfrage, falls keine Eintraege vorhanden sind. Ansonsten alle Rausschreiben. if($AnzahlEintrage -eq 0){ " " | Out-File $dest -Append "Keine Eintrage" | Out-File $dest -Append " " | Out-File $dest -Append "############################################################################################################################################################################################" | Out-File $dest -Append } else{ Get-Content -Path $LogFileFinal | Select-String -Pattern $Suchkriterium | Select-String -Pattern $UntersuchungsZeitraum | Select-Object -Property <#LineNumber,#> Line | Out-File $dest -Append " " | Out-File $dest -Append "############################################################################################################################################################################################" | Out-File $dest -Append } } } #--------------------------------------------------------------------------------- $result = $form.ShowDialog() if ($result -eq [Windows.Forms.DialogResult]::OK) { $DatumVon = $calendarVon.SelectionStart $DatumBis = $calendarBis.SelectionStart $Suchbegriff = $textBox.Text #$SucheIn = $Load #$textBoxOffnen.Text #$SpeichernIn = $textBoxSpeicher.Text # $Load Write-Host "Date selected: $($DatumVon.ToShortDateString()) und $($DatumBis.ToShortDateString()) fur die Suche nach $($Suchbegriff)" LogsAuslesen -StartDatum $DatumVon -EndDatum $DatumBis -quelle $OrdnerMitLogs -Suchkriterium $Suchbegriff -dest $PfadTxtDatei -LogName $NameLogFile }
×
×
  • Neu erstellen...