thank you for looking. I want to loop through each item in a folder and add qualifying file names and lengths (sizes) to an array so I can send an email out. For example, if there are files without the .txt extension, I do not want to include them. What happens is the email is sent out, but lists the same files in several tables. I know if the issue is how I'm storing the current file to the array, but not sure how to fix it. I just want the current file in the foreach to be added once.
Here is my stripped out code:
$myFolder = "C:\Users\myName\Documents\Temporary"
$ReceivedCount = 0
$a = "<style>BODY{font-family: Verdana; font-size: 9pt;}"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse; }"
$a = $a + "TH{border-width: 2px;padding: 7px;border-style: solid;border-color: black;background-color:lightblue;padding-right: 2px;}"
$a = $a + "TD{border-width: 2px;padding: 5px;border-style: solid;border-color: black;background-color:white; padding-right: 2px;}"
$a = $a + "</style>"
foreach ($file in $myFolder)
{
$FileName = $file.name
Echo "Curent file: $FileName"
if($FileName -like "*.txt")
{
$ReceivedCount += 1
# This is the section I'm doing wrong:
$FilesReceived += @(Select-Object name , length | ConvertTo-HTML -head $a)
}
}
Echo "Found $ReceivedCount files."
if ($FilesReceivedCount -gt 0)
{
#send email...
}
FilesReceived? What object(s) isSelect-Objectoperating on there?convertto-htmlonce for each file. If you want a single table I believe you need to run it once over the whole collection.