0

我有一张由不同领域的工作项目组成的表格。这是表格布局:

$table = @{Expression = {$_.Fields['Id'].Value}; Label = "Id"}, 
@{Expression = {$_.Fields['Work Item Type'].Value}; Label = "Work Item Type"}, 
@{Expression = {$_.Fields['Title'].Value}; Label = "Title"}, 
@{Expression = {$_.Fields['State'].Value}; Label = "State"},
@{Expression = {$_.Fields['Substate'].Value}; Label = "Substate"}, 
@{Expression = {$_.Fields['Assigned To'].Value}; Label = "Assigned To"}, 
@{Expression = {$_.Fields['CreatedBy'].Value}; Label = "Developer"},
@{Expression = {$_.Fields['QA Responsible'].Value}; Label = "QA Responsible"},
@{Expression = {$_.Fields['Iteration Path'].Value}; Label = "Iteration Path"}

从这行代码$workItems | Format-Table $table | Out-String我得到一个像这样的表:

         Id Work Item Type  Title          State          Substate       Assigned To    Developer      QA Responsible    Iteration Path
         -- --------------  -----          -----          --------       -----------    ---------      -----------    --------------
      38479 Bug             Title1000000...Resolved       zzzzzzzzzzz... xxxxxxxxxxx... zzzzzzzzzzz... zzzzzzzzzzz     QA\2012 August
      34917 Task            Title2000000...Resolved       zzzzzzzzzzz... xxxxxxxxxxx                                  WebXXX\CCCCCC 

但是当我尝试将其转换为 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>305</td></tr>
</table>
</body></html>

我只想用 HTML 格式化表格并通过电子邮件发送。我可以得到任何帮助吗?

4

2 回答 2

1

删除Out-Stringcmdlet 的管道并重试,Out-String将您的对象转换为字符串:

$workItems | Format-Table $table | ConvertTo-Html
于 2012-09-05T09:48:20.433 回答
0

好的,在谢伊的帮助下,我想通了。如果有人遇到类似问题,我会在这里发布答案。修复就在这条线上$workItems | Format-Table $table | ConvertTo-Html。它需要更改为$workItems | Select-Object $table | ConvertTo-Html.

谢伊你帮了我很多次,如果你碰巧在萨拉热窝,我会请你喝一杯:)

于 2012-09-05T10:40:13.570 回答