Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

Why won't powershell believe me?

I'm running a script from visual studio.
My script calls a setup script, which also reads an xml file.
The xml file has a template message for the html body much like:
<FailedNotice>The process failed.  The error code is {0}.  Please see &lt;a href=http://somewhere>online documentation&lt;/a&gt; for instructions</FailedNotice>


In my setup script, I set a variable to this:
[string]$FailedNotice = [system.web.httputility]::htmldecode($settings.config.Templates.FailedNotice)

When my script concludes, if the proper exit code is found for a failure, it sends a message with the htmlbody:
[string]$body = $FailedNotice -f $errorCode

However, my body continues to be displayed in the email as an system.xml.xmlelement

To fix it, I apparently had to change it to
[string]$body = ($FailedNotice -f $errorCode).tostring()
But I want to know why?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sirbounty

ASKER

So it sounds like I can either leave it as-is, or
$FailedNotice = ([system.web.httputility]::htmldecode($settings.config.Templates.FailedNotice)).tostring()

or possibly
$body = $FailedNotice.tostring() -f $errorCode

I'll give it a try.  Thanks.