none
$body += add regular text? RRS feed

  • Question

  • Hi,

    I have a script that is sending a report to my mail. It works fine as long as I don't comment out the # in this script, then it shows the mail as:

    App-V Packages deployed:----------------------------------------                                                                                                            App-V Packages used:----------------------------------------Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData

    Ho can I make titles for the subsections of my report (subsections are "App-V packaged depoyed:" and "App-V packages Used:"?

    #$body += 'App-V Packages deployed:'
    #$body += '----------------------------------------'
    $body += $AppVPackagesDeployed
    # $body + = "`"

    #$body += 'App-V Packages Used:'
    #$body += '----------------------------------------'
    $body += $AppVPackagesUsed
    $body = $body | out-string
    Send-MailMessage -From mymail@myserver.local -To myrecepient@myserver.local -SmtpServer mailserver -Subject "Report" -Body $Body


    Jan Hoedt


    • Edited by janhoedt Tuesday, November 17, 2015 1:26 PM Update
    Tuesday, November 17, 2015 1:26 PM

Answers

  • Just a typo by jrv I think.

    $body=@()
    $body += 'App-V Packages deployed:'
    $body += '----------------------------------------'
    $body += $AppVPackagesDeployed
    $body += '`'
    $body += 'App-V Packages Used:'
    $body += '----------------------------------------'
    $body += $AppVPackagesUsed
    $body = $body | out-string

    • Marked as answer by janhoedt Tuesday, November 17, 2015 2:36 PM
    Tuesday, November 17, 2015 2:26 PM

All replies

  • $body=@()$body += 'App-V Packages deployed:'
     $body += '----------------------------------------'
    $body += $AppVPackagesDeployed
    $body + = "`"
    $body += 'App-V Packages Used:'
    $body += '----------------------------------------'
    $body += $AppVPackagesUsed
    $body = $body | out-string

    \_(ツ)_/

    • Proposed as answer by Josh Lavely Tuesday, November 17, 2015 1:50 PM
    Tuesday, November 17, 2015 1:31 PM
  • Thanks but doen't work for me. I get "unexpected token $body".

    Jan Hoedt

    Tuesday, November 17, 2015 2:13 PM
  • Just a typo by jrv I think.

    $body=@()
    $body += 'App-V Packages deployed:'
    $body += '----------------------------------------'
    $body += $AppVPackagesDeployed
    $body += '`'
    $body += 'App-V Packages Used:'
    $body += '----------------------------------------'
    $body += $AppVPackagesUsed
    $body = $body | out-string

    • Marked as answer by janhoedt Tuesday, November 17, 2015 2:36 PM
    Tuesday, November 17, 2015 2:26 PM
  • Thanks, that makes more sense. Would you care mentioning what this @() does in this case/why it helps formatting the mailbody correctly?

    Jan Hoedt

    Tuesday, November 17, 2015 2:37 PM
  • It declares your $body variable as an array.  So $body builds as a collection of the objects you pass to it.  The way you had it originally $body would have been a string and each time you used the += operator powershell would attempt to append to that string.
    Tuesday, November 17, 2015 2:46 PM