PowerShell version 1.0 - Write to the event log

痴心易碎 提交于 2019-12-10 19:32:49

问题


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.

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.


回答1:


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)



回答2:


You can probably just access the .NET EventLog class to write to the log.



来源:https://stackoverflow.com/questions/10337059/powershell-version-1-0-write-to-the-event-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!