0

我有一个 Windows 表单(在 PowerShell 中),该表单有一个带有 onclick 事件的按钮,但 onclick 中的命令没有运行。我不知道为什么,因为它可以单独运行。我的 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()

请帮助解决我的问题。提前谢谢!

4

1 回答 1

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
于 2017-10-05T16:48:38.753 回答