Get-WinEvent转换为html在输出表中只有一行

时间:2014-09-22 15:12:46

标签: html events powershell

我试图将所有特定事件输出到html,并且始终只获取表格中的最后一行。

以下是HTML代码 -



Get-WinEvent -FilterHashtable @{logname='System'; id=1074}  |
ForEach-Object {

    $rv = New-Object PSObject | Select-Object Date, User, Action, Process, Reason, ReasonCode, Comment
    $rv.Date = $_.TimeCreated
    $rv.User = $_.Properties[6].Value
    $rv.Process = $_.Properties[0].Value
    $rv.Action = $_.Properties[4].Value
    $rv.Reason = $_.Properties[2].Value
    $rv.ReasonCode = $_.Properties[3].Value
    $rv.Comment = $_.Properties[5].Value
    $rv
}

#this style reason for restart.
$header = "<H3>Print Server Log Report "+(get-date -f D)+"</H3>"  
$title = "Example HTML Output" 
$body = '<style>  
BODY{font-family:Verdana; background-color:white;}  
TABLE{border-width: 1px;border-style:solid;border-color: black;border-collapse: collapse;}  
TH{font-size:1em; border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#C2B8AF}  
TD{border-width: 1px;padding: 5px;border-style:  solid;border-color: black;background-color:#F6F8FC}  
</style>'

$rv | Select-Object Date,User, Action, Reason, Comment | Convertto-html -head $header -body $body > c:\scripts\test.html
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

你有一个foreach循环,你在循环中设置了一个$ rv对象,但是看起来你没有在循环中用$ rv对象做其他事情。

如果你想要所有你正在预备的东西,打印,输出,等等,而不仅仅是最后一个,你必须在循环中打印,输出,无论什么, < / em>不在它之外。在循环之后执行此操作,您将只获得最后一个。