powershell将数据做成html,使用Powershell通过HTML格式的电子表格格式化输出

本文介绍了一种使用Powershell从CSV文件读取数据并构建HTML格式表格的方法,该表格随后被嵌入到电子邮件正文中发送出去。示例代码展示了如何筛选特定规则的数据项,并针对每个符合条件的用户ID创建表格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我试图从数组中构建表格,然后将其放入电子邮件中。我可以让表格显示数组中的第一个项目,但无法获取要列出的其余项目。我觉得我很接近,对我可能错过的东西有任何想法。使用Powershell通过HTML格式的电子表格格式化输出

$global:Report = "C:\TEMP\Scripts\PowerShell\ReadExcelFiles\File.csv"

$UViolation = import-csv $global:Report -Delimiter ' ' | Where-Object {$_.Rules -eq "TESTTEXTINFILE"}

$UserViolationDetails = New-Object System.Collections.ArrayList

foreach ($item in $UViolation){

if ($item.Destination -notcontains "HP ") {

$UserViolationDetails += ,@($item.'User Name', $item.'Occurred (Endpoint)',$item.'IP Address',$item.'Computer Name',$item.Destination)

}

}

$UserID = "USERID01"

$events = $UserViolationDetails -match $UserID

$count = 0

foreach ($line in $events){

$count++

$table = @(@{'User ID'=$line[0]; 'DateTime'=$line[1]})

}

$count

$table.ForEach({[PSCustomObject]$_}) | Format-Table -AutoSize

$ol = New-Object -comObject Outlook.Application

$mail = $ol.CreateItem(0)

$mail.To = "$global:UserReportsToEmail"

$mail.cc = "[email protected]"

$mail.Subject = "mySubject"

$mail.HTMLBody =

"TESTING STUFFFF!

Text on a new line $UserID
$table"

$inspector = $mail.GetInspector

$inspector.Display()

2016-10-26

MrMr

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值