问题描述
在我的脚本中,我收集了所有要用不同变量报告的数据。现在我试图生成一个HTML表,所以我可以通过邮件发送。
我想要实现的是HTML代码,它生成此代码:
您可以做的是将数据作为csv传递,然后使用 convertfrom-csv 将其转换为psobject运行 convertto-html :
$ Table = @
'\\Domain\NLD Users' ,'2','6','2'
'\\Domain\FRA Users','5','7','0'
@
$表| | ConvertFrom-Csv -Header'OU','登录脚本不正确','名称不正确','没有说明'| ConvertTo-Html -Fragment -As Table
In my script I've collected all the data I want to report in different variables. Now I'm trying to generate an HTML-table so I can send this by mail.
What I would like to achieve is HTML-code that generates this:
OU | Logon scripts incorrect | Name incorrect | No description \\Domain\NLD Users | 2 | 6 | 2 \\Domain\FRA users | 5 | 7 | 0 \\Domain\BEL users | 6 | 1 | 1 TOTAL USERS: 2048 | 13 | 14 | 3I'm a bit confused on what would be the best approach for this (array, psobject, hashtable, ..). Because I'm not going to work with a foreach loop, the data would be static.
What I tried so far but isn't quite giving the desired result:
$Table = @( ('OU', 'Logon scripts incorrect', 'Name incorrect', 'No description'), ('\\Domain\NLD Users','2','6','2' ), ('\\Domain\FRA Users','5','7','0' ), ('\\Domain\BEL Users','6','1','1' ), ('TOTAL USERS: 2048','13','14','3' ) ) $Table | ConvertTo-Html -As Table -FragmentIt feels like I'm over-complicating things.
解决方案convertto-html is waiting for a psobject as its input.What you can do is pass your data as csv then use convertfrom-csv to tansform it to psobject the run convertto-html :
$Table = @" '\\Domain\NLD Users','2','6','2' '\\Domain\FRA Users','5','7','0' "@ $Table | ConvertFrom-Csv -Header 'OU', 'Logon scripts incorrect', 'Name incorrect', 'No description' | ConvertTo-Html -Fragment -As Table
这篇关于PowerShell构建一个2D HTML表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!