event log thingie

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 3 months, 3 weeks ago.

  • Author
    Posts
  • #62875
    Profile photo of Aapeli Hietikko
    Aapeli Hietikko
    Participant

    colleague of mine asked me to tweak his event log for dummies script. I'm not sure if there is any use for it, but I thought I would share it as it turned to be something different from the same-same old functions

    
    Add-Type -AssemblyName System.Windows.Forms
    # Main Form
    $mainForm = New-Object System.Windows.Forms.Form
    $font = New-Object System.Drawing.Font(“Consolas”, 13)
    $mainForm.Text = ” Pick Time Frame”
    $mainForm.Font = $font
    $mainForm.ForeColor = 'black'
    $mainForm.BackColor = 'white'
    $mainForm.Width = 500
    $mainForm.Height = 500
    
    # DatePicker Label
    $startDatePickerLabel = New-Object System.Windows.Forms.Label
    $startDatePickerLabel.Text = “start date”
    $startDatePickerLabel.Location = “15, 10”
    $startDatePickerLabel.Height = 22
    $startDatePickerLabel.Width = 120
    $mainForm.Controls.Add($startDatePickerLabel)
    
    # MinTimePicker Label
    $minTimePickerLabel = New-Object System.Windows.Forms.Label
    $minTimePickerLabel.Text = “start time”
    $minTimePickerLabel.Location = “15, 45”
    $minTimePickerLabel.Height = 22
    $minTimePickerLabel.Width = 120
    $mainForm.Controls.Add($minTimePickerLabel)
    
    # DatePicker Label
    $EndDatePickerLabel = New-Object System.Windows.Forms.Label
    $EndDatePickerLabel.Text = “End Date”
    $EndDatePickerLabel.Location = “15, 80”
    $EndDatePickerLabel.Height = 22
    $EndDatePickerLabel.Width = 120
    $mainForm.Controls.Add($EndDatePickerLabel)
    
    # MaxTimePicker Label
    $maxTimePickerLabel = New-Object System.Windows.Forms.Label
    $maxTimePickerLabel.Text = “End time”
    $maxTimePickerLabel.Location = “15, 115”
    $maxTimePickerLabel.Height = 22
    $maxTimePickerLabel.Width = 120
    $mainForm.Controls.Add($maxTimePickerLabel)
    
    # tBoxComputerName Label
    $tBoxComputerNameLabel = New-Object System.Windows.Forms.Label
    $tBoxComputerNameLabel.Text = “computer”
    $tBoxComputerNameLabel.Location = “15, 150”
    $tBoxComputerNameLabel.Height = 22
    $tBoxComputerNameLabel.Width = 120
    $mainForm.Controls.Add($tBoxComputerNameLabel)
    
    # EventLog Label
    $eventLogLabel = New-Object System.Windows.Forms.Label
    $eventLogLabel.Text = “EventLog”
    $eventLogLabel.Location = “15, 185”
    $eventLogLabel.Height = 22
    $eventLogLabel.Width = 120
    $mainForm.Controls.Add($eventLogLabel)
    
    # startDatePicker
    $startDatePicker = New-Object System.Windows.Forms.DateTimePicker
    $startDatePicker.Location = “140, 7”
    $startDatePicker.Width = “150”
    $startDatePicker.MaxDate = $(get-date)
    $startDatePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $startDatePicker.CustomFormat = “dd/MM/yyyy”
    $mainForm.Controls.Add($startDatePicker)
    
    # startTimePicker
    $startTimePicker = New-Object System.Windows.Forms.DateTimePicker
    $startTimePicker.Location = “140, 42”
    $startTimePicker.Width = “150”
    $startTimePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $startTimePicker.CustomFormat = “HH:mm:ss”
    $startTimePicker.ShowUpDown = $TRUE
    $mainForm.Controls.Add($startTimePicker)
    
    # endDatePicker
    $endDatePicker = New-Object System.Windows.Forms.DateTimePicker
    $endDatePicker.Location = “140, 77”
    $endDatePicker.Width = “150”
    $endDatePicker.MaxDate = $(get-date)
    $endDatePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $endDatePicker.CustomFormat = “dd/MM/yyyy”
    $mainForm.Controls.Add($endDatePicker)
    
    # EndTimePicker
    $endTimePicker = New-Object System.Windows.Forms.DateTimePicker
    $endTimePicker.Location = “140, 112”
    $endTimePicker.Width = “150”
    $endTimePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $endTimePicker.CustomFormat = “HH:mm:ss”
    $endTimePicker.ShowUpDown = $TRUE
    $mainForm.Controls.Add($endTimePicker)
    
    # computername
    $tBoxComputerName = New-Object System.Windows.Forms.TextBox 
    $tBoxComputerName.Location = New-Object System.Drawing.Size("140,147")
    $tBoxComputerName.Size = New-Object System.Drawing.Size("260,20") 
    $mainForm.Controls.Add($tBoxComputerName) 
    
    # eventlog list box
    
    
    $eventLogBox = New-Object System.Windows.Forms.ListBox 
    $eventLogBox.Location = New-Object System.Drawing.Point(140,182) 
    $eventLogBox.Size = New-Object System.Drawing.Size(260,40) 
    $eventLogBox.Height = 120
    
    $options =  "Error","Information","FailureAudit","SuccessAudit","Warning"
    
    foreach ($option in $options) {
    
        [void] $eventLogBox.Items.Add($option)
        
        }
    
    $mainForm.Controls.Add($eventLogBox) 
    
    # OD Button
    $okButton = New-Object System.Windows.Forms.Button
    $okButton.Location = “15, 400”
    $okButton.ForeColor = “Black”
    $okButton.BackColor = “White”
    $okButton.Text = “OK”
    $okButton.add_Click({$mainForm.close()})
    $mainForm.Controls.Add($okButton)
    
    
    [void] $mainForm.ShowDialog()
    
    $outStartDate = get-date ($startDatePicker.Value.Date)
    $outStartDate = $outStartDate.AddHours($startTimePicker.Value.Hour).AddMinutes($startTimePicker.Value.Minute).AddSeconds($startTimePicker.Value.Second)
    
    $outEndDate = get-date ($endDatePicker.Value.Date)
    $outEndDate = $outEndDate.AddHours($endTimePicker.Value.Hour).AddMinutes($endTimePicker.Value.Minute).AddSeconds($endTimePicker.Value.Second)
    
    if ($outEndDate -gt (Get-Date)) {$outEndDate = Get-Date}
    
    
    
    Get-EventLog -ComputerName $tBoxComputerName.Text -LogName System -After $outStartDate -Before $outEndDate -EntryType $eventLogBox.Text | Out-GridView
    
    
  • #63039
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Thank you!!

You must be logged in to reply to this topic.