【问题标题】:PowerShell version 1.0 - Write to the event logPowerShell 1.0 版 - 写入事件日志
【发布时间】:2012-04-26 15:58:43
【问题描述】:

我们有一个使用 PowerShell 1.0 的客户端。我知道在 PowerShell 2.0 中,我有 Write-EventLog commandlet。但是,这不会出现在 PowerShell 1.0 中。我希望我的脚本将事件记录到事件日志中,主要用于调试目的。

如何使用 PowerShell 1.0:?而且,不,我无法将此计算机升级到 PowerShell 2.0。这是一台客户生产机器,他们不想触摸上面的软件。

【问题讨论】:

    标签: powershell event-log


    【解决方案1】:

    您可以使用 .NET EventLog 类来执行此操作。使用起来非常简单,例如:

    $eventSource = "MyAppName"
    if (![Diagnostics.EventLog]::SourceExists($eventSource))
    {
        [Diagnostics.EventLog]::CreateEventSource($eventSource, "Application")
    }
    
    [Diagnostics.EventLog]::WriteEntry($eventSource, "message", [Diagnostics.EventLogEntryType]::Error)
    

    【讨论】:

    • 谢谢。那成功了。我试图先创建一个对象,但这更容易。
    【解决方案2】:

    您可能只需访问.NET EventLog class 即可写入日志。

    【讨论】:

      猜你喜欢
      • 2014-10-29
      • 2022-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      相关资源
      最近更新 更多