PowerShell版本1.0-写入事件日志 [英] PowerShell version 1.0 - Write to the event log

查看:92
本文介绍了PowerShell版本1.0-写入事件日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have a client with PowerShell 1.0. I know in PowerShell 2.0, I have the Write-EventLog commandlet. However, this doesn't appear in PowerShell 1.0. I want my script to log events to the event log, mainly for debugging purposes.

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

How can I do this with PowerShell 1.0:? And, no I can't upgrade this computer to PowerShell 2.0. This is a customer production machine, and they don't want to touch the software on it.

推荐答案

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

You can use the .NET EventLog class to do this. It is pretty simple to use e.g.:

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

[Diagnostics.EventLog]::WriteEntry($eventSource, "message", [Diagnostics.EventLogEntryType]::Error)

这篇关于PowerShell版本1.0-写入事件日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆