2017-10-05 81 views
0

我有一个Windows窗体(在PowerShell中),并且窗体有一个onclick事件按钮,但onclick中的命令未运行。我不知道为什么,因为它可以运行sepratley。我的sciptblock在这里:Powershell Windows窗体onClick事件

[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() 

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

+0

你没有定义$ A2 – ArcSet

回答

1

2东西

你没有定义$一个

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 
+0

对不起,我有一个错误表明我的$的定义,但你的answare是为我好,用| Out-Host管道!非常感谢ArcSet! –