這個問題有兩部分:最終我試圖從檔案描述和原始檔案名中列印出資料。第一個也是可能很簡單的問題是我如何在同一條線上獲得它們?我正在使用PS G:\SysinternalsSuite> $values=@("filedescription", "originalfilename");foreach($V in $Values){(get-command g:\*\*\a*.exe).fileversioninfo.($v)} Windows Assessment and Deployment Kit - Windows 10 adksetup.exe兩條線,而不是一條線。之后我可以編輯它,但是...
下一個問題是嘗試將此資訊輸出到檔案:我正在使用(get-command g:\*\*\a*.exe).fileversioninfo.filedescription回傳 exe 檔案檔案夾的美化名稱(在此示例中。我正在使用 SysInternalsSuite) 結果:
PS G:\SysinternalsSuite> (get-command g:\*\*\a*.exe).fileversioninfo.filedescription
Windows Assessment and Deployment Kit - Windows 10
作業得很好......然后一切都錯了!我的下一個想法是將這些值放入一個 HTML 檔案中,所以我這樣做了:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/></colgroup>
<tr><th>*</th></tr>
<tr><td>50</td></tr>
</table>
</body></html>```
WTH are all these numbers??? Where's my data? Fine...
```PS G:\SysinternalsSuite> (get-command g:\*\*\a*.exe).fileversioninfo.filedescription | echo
Windows Assessment and Deployment Kit - Windows 10```
Perfect!
```PS G:\SysinternalsSuite> (get-command g:\*\*\a*.exe).fileversioninfo.filedescription | echo | convertTo-HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/></colgroup>
<tr><th>*</th></tr>
<tr><td>50</td></tr>
</table>
</body></html>
write GRRRR!!!!
好的!我在這里缺少什么?
uj5u.com熱心網友回復:
ConvertTo-Html 通過檢查通過管道傳輸到它的任何物件的屬性,并創建一個表,其中每列對應于屬性名稱。
由于該[string]型別只有一個屬性 -Length屬性 - 這就是您在 html 表中獲得的內容 - 具有每個輸入字串長度的單個列。
相反,發送一個物件,其中描述是屬性的值,然后在表中指定所需的屬性串列:
(Get-Command g:\*\*\a*.exe).FileVersionInfo |ConvertTo-Html FileDescription
uj5u.com熱心網友回復:
function HtmlTable
{
[OutputType([System.Object])]
Param (
[Parameter(Mandatory=$True)]
[String[]]
$tableRows,
[Parameter(Mandatory=$True)]
[String[]]
$tableHeaders,
[Parameter(Mandatory=$True)]
$tableWidthPercentage
)
$htmTable = "<html>
<style>
body {font-family:Segoe UI, Helvetica Neue, Helvetica, Arial, Verdana;font-size:12px;}
table{width: $tableWidthPercentage;border-collapse: collapse;}
th{background-color:#106ebe; color:white;font-family:Segoe UI, Helvetica Neue, Helvetica, Arial, Verdana;font-size:12px;border: 1px solid black;padding: 4px;text-align: left;border: 1px solid #ddd;}
tr:nth-child(even){background-color: #f2f2f2;}
td{font-family:Segoe UI, Helvetica Neue, Helvetica, Arial, Verdana;font-size:12px;border: 1px solid #ddd;padding: 4px;}
</style>
<table>
<tr>"
Foreach ($header in $tableHeaders)
{
$htmTable = "<th>$header</th>"
}
$htmTable ="</tr>
$tableRows
</table>"
return $htmTable
}
#simply you can call the function directly as below, where $tableData is the variable you can give the td data
$htmlTemplate= HtmlTable -tableWidthPercentage 80% -tableRows $tableData -tableHeaders ID,CreatedDate,Title,State,Efforts
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/328034.html
