Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell输出到HTML_Powershell - Fatal编程技术网

PowerShell输出到HTML

PowerShell输出到HTML,powershell,Powershell,使用下面的代码,希望知道如何将结果输出到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

使用下面的代码,希望知道如何将结果输出到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

如果我说:
converttohtml
是您所需要的,那么这可能足以添加注释

相反,我会说:在PowerShell外部提问之前,先在PowerShell内部提问

Get-Help *html*

这将使它打印出漂亮的颜色。你可以随意修改它,想做什么就做什么

$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
$a=“”
$a=$a+“主体{背景色:桃红色;}”
$a=$a+“表{边框宽度:1px;边框样式:实心;边框颜色:黑色;边框折叠:折叠;}”
$a=$a+“TH{边框宽度:1px;填充:0px;边框样式:纯色;边框颜色:黑色;背景颜色:蓟叶}”
$a=$a+“TD{边框宽度:1px;填充:0px;边框样式:纯色;边框颜色:黑色;背景颜色:淡黄色}”
$a=$a+“”
$Variable=get-what\u I\u
$Variable2=得到我想要的东西
$VariableHTML=$Variable | ConvertTo HTML-head$a-body“Title I want”
$Variable2HTML=$Variable2 |转换为HTML-标题$a-正文“标题一标题二标题三段落

” $VariableHTML>C:\PoSH\My\u Exported\u HTML.HTML

我添加了第二个变量。如您所见,您可以添加不同级别的标题和段落。我发现这对单行项目很有帮助,或者如果您想要更好的描述