英文:
Pwershell : Converting multiple HTML data to HTML table
问题
我是新的PowerShell。以下是我的代码快照:
$test = New-Object System.Collections.ArrayList
-----
ForEach($list in $runs.steps)
{If($list.name ) {
------
----
$test.add(""$($list.name) - $($Result) - $($Post)"")
}
}**
我想以以下HTML表格格式显示list.name,result和Post,表头分别为"Name","Result","Post"。请帮我完成。
英文:
I am new powershell. Below is snapshot of my code:
$test = New-Object System.Collections.ArrayList
-----
ForEach($list in $runs.steps)
{If($list.name ) {
------
----
$test.add("$($list.name) - $($Result) - $($Post)")
}
}**
I want to display list.name , result and Post in to following HTML table format with header "Name", "Result", "Post". Please help me
答案1
得分: 0
你会想要构建 _objects_,属性名称对应于你想要的表格列标题:
```powershell
foreach($list in $runs.steps) {
if($list.name) {
[void]$test.Add([pscustomobject]@{
Name = $list.name
Result = $Result
Post = $Post
})
}
}
现在你可以通过将对象传递给 ConvertTo-Html
来构建所需的HTML表格:
$htmlTableFragment = $test | ConvertTo-Html -Fragment -As Table
英文:
You'll want to construct objects with property names corresponding to the table column headers you want:
foreach($list in $runs.steps) {
if($list.name) {
[void]$test.Add([pscustomobject]@{
Name = $list.name
Result = $Result
Post = $Post
})
}
}
Now you can construct the desired html table by simply piping the objects to ConvertTo-Html
:
$htmlTableFragment = $test |ConvertTo-Html -Fragment -As Table
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论