我想使用搜索选项将powershell输出转换为HTML格式。 我有jscript / css的HTML,我试图在我的Powershell代码中添加到HTML样式中。 搜索选项不是在页面中搜索数据。
HTML代码
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url('/css/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#myTable th, #myTable td {
text-align: left;
padding: 12px;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h2>My Customers</h2>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name">
<table id="myTable">
<tr class="header">
<th style="width:60%;">Name</th>
<th style="width:40%;">Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Germany</td>
</tr>
</table>
<script>
function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</body>
</html>
我想要这个html格式表来获取命令的输出 获取服务。
$services = Get-Service
$FullHTML = $services | select Name,StartType -First 5 | ConvertTo-Html -Fragment
答案 0 :(得分:0)
这是一种方法:
然后,您可以运行以下命令以生成可搜索的HTML页面:
$template = Get-Content ".\template.txt" -Raw
$table = (Get-Service | select Name,StartType | ConvertTo-Html -Fragment).Replace('<table>', '<table id="myTable">')
$template.Replace("`$table", $table) | Out-File .\Services.html