PowerShell:将多个HTML数据转换为HTML表格

huangapple go评论52阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年7月3日 22:25:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605683.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定