Событие PowerShell для Windows Forms onClick
У меня есть формы Windows (в PowerShell), и форма имеет кнопку с событием onclick, но команда в onclick не запускается. Я не знаю почему, потому что это может быть запущен sepratley. Мой sciptblock здесь:
[void][reflection.assembly]::loadwithpartialname("System.Windows.Forms")
$form = New-Object System.Windows.Forms.Form
$form.Width = 500
$form.Height = 200
$form.formborderstyle = 3
$form.StartPosition = "CenterScreen"
$button1 = New-Object System.Windows.Forms.Button
$button1.Text = "Search"
$button1.Height = 25
$button1.Width = 85
$button1.Top = 100
$button1.Left = 25
$button1_OnClick =
{
Get-EventLog -LogName Security -After $a2.Value.Date | Where-Object
{$_.EventID -eq "4800" -or $_.EventID -eq "4801"} | Format-Table
}
$button1.add_Click($button1_OnClick)
$form.Controls.Add($button1)
$form.ShowDialog()
Пожалуйста, помогите решить мою проблему. Спасибо заранее!
1 ответ
Решение
2 вещи
Вы не определили $a в
Get-EventLog -LogName Security -After $a2.Value.Date
Во-вторых, вы не решили, как вывести таблицу. Вы можете сделать что-то вроде...
Get-EventLog -LogName Security -After $a2.Value.Date | Where-Object{$_.EventID -eq "4800" -or $_.EventID -eq "4801"} | Format-Table | Out-Host