뭔가가 작동해야합니다.
단일 테이블
Get-Content "C:\Dv\Server_List.txt" -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "Automatic Services Stopped :" $_
Get-WmiObject Win32_Service -ComputerName $_ -Filter "startmode = 'auto' AND state != 'running'"
} |
Select-Object DisplayName, Name, State, StartMode |
ConvertTo-Html |
Out-File C:\Dv\Report.html
여러 테이블
이 버전은 ConvertTo-Html -Fragment
를 사용하여 테이블의 순서를 만듭니다. 각 테이블 앞에는 컴퓨터 이름이있는 HTML 헤더 (예제에서는 h2)가옵니다. 각각의 테이블은 ConvertTo-Html
에 대한 베어 (입력 없음) 호출을 사용하여 마지막에 단일 HTML 문서로 연결되고 병합됩니다.
# Generate the content which should be inserted as a set of HTML tables
$preContent = Get-Content "C:\Dv\Server_List.txt" -ErrorAction SilentlyContinue | ForEach-Object {
$ComputerName = $_
Write-Host "Automatic Services Stopped :" $ComputerName
# A table (and heading) will only be generated for $ComputerName if there are services matching the filter.
Get-WmiObject Win32_Service -ComputerName $ComputerName -Filter "startmode = 'auto' AND state != 'running'" |
Select-Object DisplayName, Name, State, StartMode |
ConvertTo-Html -PreContent "<h2>$ComputerName</h2>" -Fragment
}
# Generate the document which holds all of the individual tables.
$htmlDocument = ConvertTo-Html -Head $htmlHead -PreContent $preContent | Out-String
# Because the document has no input object it will have an empty table (<table></table>), this should be removed.
$htmlDocument -replace '<table>\r?\n</table>' | Out-File C:\Dv\Report.html
스타일링
당신은 꽤 원료로 이들에 의해 생성 된 HTML을 찾을 수 있습니다.
$HtmlHead = '<style>
body {
background-color: white;
font-family: "Calibri";
}
table {
border-width: 1px;
border-style: solid;
border-color: black;
border-collapse: collapse;
width: 100%;
}
th {
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: black;
background-color: #98C6F3;
}
td {
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: black;
background-color: White;
}
tr {
text-align: left;
}
</style>'
# Use the Head parameter when calling ConvertTo-Html
... | ConvertTo-Html -Head $HtmlHead | ...
참고 : 다음 조각 매개 변수가 하지 ConvertTo-와 함께 제공되는 때 머리에만 적용를 해결하기 위해 더 나은 방법 중 하나는 여기에 HTML 테이블이 예뻐 보일 수 있습니다 내 조각이야, CSS를 사용하는 것입니다 Html.
'ConvertTo-Html'을 사용하십시오. –