【问题标题】:Powershell Windows Forms onClick eventPowershell Windows 窗体 onClick 事件
【发布时间】:2018-03-17 06:27:48
【问题描述】:

我有一个 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()

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

【问题讨论】:

  • 你没有定义$A2

标签: winforms powershell get-eventlog


【解决方案1】:

两件事

你没有在

中定义$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

【讨论】:

  • 抱歉,我在显示 $a 定义时出错了,但是您的回答对我有好处 |主机外管道!非常感谢 ArcSet!
猜你喜欢
  • 2018-12-10
  • 1970-01-01
  • 2017-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-20
  • 1970-01-01
相关资源
最近更新 更多