2014-06-24 17 views
1

使用以下,並想知道如何將結果輸出到HTML文件PowerShell的outtput爲HTML

$Start = (Get-Date).AddMinutes(-5) 
$Computername = gc C:\Temp\List.txt 
$Events = gc C:\Temp\ErrorCodes.txt 

Get-EventLog -AsString -ComputerName $Computername | 
ForEach-Object { 
# write status info 
Write-Progress -Activity "Checking Eventlogs on \\$ComputerName" -Status $_ 

# get event entries and add the name of the log this came from 
Get-EventLog -LogName $_ -EntryType Error, Warning -After $Start -ComputerName $ComputerName -ErrorAction SilentlyContinue | 
    Add-Member NoteProperty EventLog $_ -PassThru | Where-Object {$Events -contains $_.eventid} 

} | 
# select the properties for the report 
Select-Object EventLog, EventID, TimeGenerated, EntryType, Source, Message 

回答

2

這會讓它打印出漂亮的顏色。你可以修補它並改變任何你想要的。

$a = "<style>" 
$a = $a + "BODY{background-color:peachpuff;}" 
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color:black;border-collapse: collapse;}" 
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" 
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}" 
$a = $a + "</style>" 

$Variable = get-what_I_want 
$Variable2 = get-what_I_want 
$VariableHTML = $Variable | ConvertTo-HTML -head $a -body "<H2>Title I want</H2>" 
$Variable2HTML = $Variable2 | ConvertTo-HTML -head $a -body "<H1>Header One</H1> <H2>Header Two</H2> <H3>Header Three</H3> <p>Paragraph<p/>" 
$VariableHTML > C:\PoSH\My_Exported_HTML.html 

我添加了第二個變量。正如你所看到的,你可以添加不同級別的標題和段落。我發現這對單行項目很有幫助,或者您希望獲得更好的描述。

1

如果我會說:ConvertTo-Html是你所需要的,可能比這將是足夠的添加評論。

相反,我會說:在PowerShell之外問問題之前,先問問他們在PowerShell內部。

Get-Help *html*