I'm attempting to build a table from an array and then place it into an email. I'm able to get the table to show the first item from the array, but can't get the rest of the items to be listed. I feel like I'm close, any ideas on what I may be missing.
$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 =
"<font color ='blue'><b>TESTING STUFFFF!</b></font><br>
Text on a new line $UserID<br>$table"
$inspector = $mail.GetInspector
$inspector.Display()