Convert empty array to text string for HTML conversion
-
Thursday, June 14, 2012 4:32 PM
I have a custom array stored as $REPORT3 that is sent as part of an HTML formatted email body using CovertTo-HTML. There may be instances when $REPORT3 is empty. Rather than just passing an e-mail body that is empty I wanted to insert a text string indicating "no matching criteria".
$REPORT3 = @()
collect data to insert into $REPORT3
message body = $REPORT3 | ConvertTo-HTML
Now suppose $REPORT3.Length -eq 0, what value can I assign to $REPORT3 such that it can be converted to HTML and still work in the above framework? I tried $REPORT3 = "no matches" and $REPORT3 = "<html> no matches /<html>" if array length is 0, but I get garbarge output from the HTML conversion (random numbers and and asterisk character).
$REPORT3 = @()
collect data to insert into $REPORT3
if ($REPORT3.length -eq 0) {$REPORT3 = ???}
message body = $REPORT3 | ConvertTo-HTML
All Replies
-
Thursday, June 14, 2012 4:58 PM
Hi,
One of several simple solutions.$REPORT3 = @() if ($REPORT3.length -eq 0) { $REPORT3 | ConvertTo-HTML -Body "no matching criteria" } else { $REPORT3 | ConvertTo-HTML }- Marked As Answer by wallst360 Thursday, June 14, 2012 11:09 PM
-
Thursday, June 14, 2012 11:10 PMThanks.

