为我的作业分配创建日志文件时遇到问题。当我开始尝试创建新的日志文件时,大多数问题都会出现。找不到日志文件的错误,并且正在使用源代码等。等。
请帮忙! :)
这是我的作业说明:
在这里输入代码
New-EventLog Application -Source Lesson12a
Write-EventLog Application -Message "THIS TEST" Lesson12a -EventId 0001
Write-EventLog Application -Message "THIS TEST2" Lesson12a -EventId 0002
Get-EventLog Application -Source Lesson12a
Remove-EventLog -Source Lesson12a
Read-Host "PAUSE"
New-EventLog MyLesson12
Read-Host "PAUSE"
Write-EventLog MyLesson12 -Message tutu1 -Source ME -EventId 0001
Write-EventLog MyLesson12 -Message tutu2 -Source ME -EventId 0002
Write-EventLog MyLesson12 -Message tutu3 -Source ME -EventId 0003
$events = Get-EventLog MyLesson12 -Newest 50 | Sort-Object Index
foreach ($element in $events )
{
$id = $element.Index.ToString()
$source = $element.Source.ToString()
$message = $element.Message.ToString()
Write-Host "$id `t $source `t`t $message"
}
Clear-EventLog -LogName MyLesson12
Get-EventLog MyLesson12
Remove-EventLog MyLesson12
答案 0 :(得分:0)
不确定发生了什么,但我能够解决我的问题。
<#New-EventLog Application -Source Lesson12a
Write-EventLog Application -Message "THIS TEST" Lesson12a -EventId 0001
Write-EventLog Application -Message "THIS TEST2" Lesson12a -EventId 0002
Get-EventLog Application -Source Lesson12a
Remove-EventLog -Source Lesson12a
Read-Host "PAUSE"#>
New-EventLog MyLesson12 -Source ME
Write-EventLog MyLesson12 -Message tutu1 -Source ME -EventId 0001
Write-EventLog MyLesson12 -Message tutu2 -Source ME -EventId 0002
Write-EventLog MyLesson12 -Message tutu3 -Source ME -EventId 0003
$events = Get-EventLog MyLesson12 -Newest 50 | Sort-Object Index
foreach ($element in $events )
{
$id = $element.Index
$source = $element.Source
$message = $element.Message
Write-Host "$id `t $source `t`t $message"
}
Clear-EventLog -LogName MyLesson12
#Write-EventLog MyLesson12 -Message 'Logs Cleared' -Source ME -EventId 1111
Get-EventLog MyLesson12
Remove-EventLog MyLesson12
#Remove-EventLog -Source ME