Variable in mail body doesnt work [SOLVED]

by lopyeg at 2013-04-26 05:02:22

Hello Scripting Folk
I try to email some info
New-Object PSObject -Property @{
Date = $date
User = $user
} -outvariable +out
Add-PSSnapin quest.activeroles.admanagement
$smtp = new-object Net.Mail.SmtpClient(“”)
$smtp.send(“,"", “IDEA Lack of licenses in $(get-date -format MMMM)”, `
"$out Total in $(get-date -format MMMM): Lacks of licenses were $($out.Count)")

So I have variable Out with hash table inside/ I try to input it to email.

I got only 1 string in the mail : “Total in April: Lacks of licenses were 25” but without content of $out behind
So it sees $($out.Count) and doesnt retransmit hashtable from $out

I tried
“[b][string]::$out[/b] Total in $(get-date -format MMMM): Lacks of licenses were $($out.Count)”
"[b]$($out.tostring())[/b] Total in $(get-date -format MMMM): Lacks of licenses were $($out.Count)"
"[b]$(write-host $out)[/b] Total in $(get-date -format MMMM): Lacks of licenses were $($out.Count)“

Nothing worked. What do i do wrong?
thanks a lot
by DonJ at 2013-04-26 07:04:39
The syntax here is a bit weird. I’m not sure why you’re using -outvariable, for example. Does $out contain anything? I’m more used to seeing…

$out += New-Object (etc)

But I guess, just confirm that $out contains something and in fact has a Count property.
by lopyeg at 2013-04-26 07:14:04
$out contains whole hashtable

if i transmit $out to text file, then from text file to $another_variable
and $another_variable use in $smtp.send() - it works, but text is twisted (formatting is awful)
by DonJ at 2013-04-26 07:24:47
Uh… sorry, I’m not following that.

What happens, in your code, if you just Write-Host “$($out.count)” Anything? Nothing?
by lopyeg at 2013-04-26 07:32:55
Write-Host “$($out.count)” returns “25” # Joking …It is close to 42

25 it is number of lines in hashtable (which is included into $out)
by lopyeg at 2013-04-26 07:35:41
and if i try
”$($out.toString()) Total in $(get-date -format MMMM): Lacks of licenses were $($out.Count)")
a get this text in email
"System.Collections.ArrayList Total in April: Lacks of licenses were 25
by ArtB0514 at 2013-04-26 07:39:08
Given that $out is a hash table, then $out.GetEnumerator() will give you the output that you want.
by lopyeg at 2013-04-26 08:01:10
$out.GetEnumerator() returns empty space in the email…
by lopyeg at 2013-04-26 08:03:21
why does it work (not fine but works) when i $out >> to text, then “gci” from text ?
by poshoholic at 2013-04-26 08:11:20
$out | Out-String
That should avoid the need to go to disk and back. Just make sure to put it in a subexpression as you already tried with $($out.ToString()).
by lopyeg at 2013-04-26 08:15:32
it works)) now it looks too easy … but i spent a few hours… thanks a lot!!! You are very open-hearted as all Guys in the forum