gpt4 book ai didi

html - PowerShell:将数组转换为html表

转载 作者:行者123 更新时间:2023-12-03 00:27:28 24 4
gpt4 key购买 nike

如何将PowerShell中的简单哈希数组转换为HTML表?

$array = @{

"Name" = "My Name"
"Surname" = "My Surname"
"Address" = "My Address"
"DateOfBirth" = "My Date Of Birth"
"Hobby" = "My Hobby"
"Age" = "My Age"
}

enter image description here

然后继续添加行?有人做到过吗?下面,我将根据几个在线论坛提供到目前为止我已经尝试过的示例:
[System.Management.Automation.PSCustomObject]$array | ConvertTo-Html
-Fragment

Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "System.Management.Automation.PSCustomObject". At line:0 char:0 + [System.Management.Automation.PSCustomObject]$array | ConvertTo-Html ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [], RuntimeException + FullyQualifiedErrorId : ConvertToFinalInvalidCastException


New-Object psobject -Property $array | ConvertTo-Html -Fragment

System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry


$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -Fragment

System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry


 $array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment

System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry


$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment | Out-String

System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry


$table = $array.GetEnumerator() | ConvertTo-Html -Fragment -As Table

enter image description here
$table = $array.GetEnumerator() | select "Name", "Surname", "Address", "DateOfBirth", "Hobby", "Age" | ConvertTo-Html -Fragment -As Table

enter image description here

如您所见,有许多不同的方法,但是没有一种方法可以成功:-(

最佳答案

你的意思是这样的吗?

$table = [PSCustomobject]$array| ConvertTo-Html -Fragment -As Table
$table
<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>Name</th><th>Age</th><th>Surname</th><th>DateOfBirth</th><th>Hobby</th><th>Address</th></tr>
<tr><td>My Name</td><td>My Age</td><td>My Surname</td><td>My Date Of Birth</td><td>My Hobby</td><td>My Address</td></tr>
</table>

您想从哪个来源添加行?

关于html - PowerShell:将数组转换为html表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53268257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com