PowerShell构建一个2D HTML表格 [英] PowerShell Build a 2D HTML table

查看:113
本文介绍了PowerShell构建一个2D HTML表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的脚本中,我收集了所有要用不同变量报告的数据。现在我试图生成一个HTML表,所以我可以通过邮件发送。



我想要实现的是HTML代码,它生成此代码:

  OU |登录脚本不正确|名称不正确|没有说明
\\Domain\NLD Users | 2 | 6 | 2
\\\Domain\FRA users | 5 | 7 | 0
\\Domain\BEL users | 6 | 1 | 1
总用户数:2048 | 13 | 14 | 3

我有点困惑什么是最好的方法(array,psobject,哈希表, ..)。因为我不打算使用foreach循环,数据将是静态的。



到目前为止我尝试过的,但没有给出理想的结果:

  $ Table = @(('OU','登录脚本不正确','姓名不正确','没有描述'),
('\\Domain\NLD Users','2 '','6','2'),
('\\Domain\FRA Users','5','7','0'),
('\\\
('TOTAL USERS:2048','13','14','3')
)用户','6','1','1'
$表| | ConvertTo-Html -As Table -Fragment

这感觉就像我过于复杂的事情。

解决方案
您可以做的是将数据作为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             | 3

I'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 -Fragment

It 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表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆