none
Mail report, format not ok RRS feed

  • Question

  • Hi,

    I'm struggling with mailing a report.
    The report works fine but when I mail it, I can't make it properly work when the output is formatted as list.
    When I do the output (a result of all App-V packages on an SCCM server) is

    Output
    ---------
    Package1 - Package 2 - Package 3

    Instead of

    Output
    ----------
    Package1
    Package2
    Package3

    Tried with all kind of formatting but can't make it work.

    This is a part of the script:

    #Body
    $body=@()
    $body += 'SCCM AppV Packages Computers:'
    $body += '-----------------------------------------------'
    $body +=  Get-CMAppVPackageComputers | Format-List

    $body = $body | out-string

    #Send mail
    Send-MailMessage -From NoReply@ourmailserver -To me@ourdomain.com -SmtpServer smtpserver-Subject "Software Report " -Body $Body



    Get-CMAppVPackageComputers is

    Get-CMApplication -Name "*AppV - Computers*"   | Select-Object LocalizedDisplayName -ExpandProperty LocalizedDisplayName | Sort-Object -Property LocalizedDisplayName

    Please advise.
    J.

     

    Jan Hoedt

    Monday, November 30, 2015 3:25 PM

Answers

  • As an alternative:

    #Body
    $body="SCCM AppV Packages Computers:`n"
    $body+= "-----------------------------------------------`n"
    $body += Get-CMAppVPackageComputers | Format-List |Out-String

    A body has to be all strings and not a string array.

    I would recommend using Bill's suggestion as it is more flexible.


    \_(ツ)_/

    • Marked as answer by janhoedt Tuesday, December 1, 2015 1:16 PM
    Monday, November 30, 2015 6:04 PM

All replies

  • You don't have control of how the mail client displays plain-text messages.

    If you want a table format, then output an HTML table and use -BodyAsHtml with Send-MailMessage.


    -- Bill Stewart [Bill_Stewart]

    Monday, November 30, 2015 3:36 PM
    Moderator
  • As an alternative:

    #Body
    $body="SCCM AppV Packages Computers:`n"
    $body+= "-----------------------------------------------`n"
    $body += Get-CMAppVPackageComputers | Format-List |Out-String

    A body has to be all strings and not a string array.

    I would recommend using Bill's suggestion as it is more flexible.


    \_(ツ)_/

    • Marked as answer by janhoedt Tuesday, December 1, 2015 1:16 PM
    Monday, November 30, 2015 6:04 PM
  • Thanks jrv, I will look into that.
    Meanwhile I was looking into what Bill suggested and created an html report.


    It works fine but it puts localizeddisplayname at the top and I can't get rid of it.

    Then also I wonder howto add simple entries before each header, f.e. for applications that would be

    $Applications = Get-CMApplication -Name "*Application*"
    $NumberOfApplications = $Applications.Count

    $frag0 = "There are $Applications.Count Applications"

    $css = @"
    
    body { 
            font-family:Tahoma;
            font-size:8pt;
            background-color:white;
            color:#333;
         }
    
    th {
            font-weight:bold;
            color:white;
            background-color:black;
    
       }
    
    .even { background-color:#eee;}
    .odd  { background-color:#eee;}
    
    "@
    
    
    
               
    
    $frag1 = Get-CMAppVPackages | Select-Object localizeddisplayname | 
             ConvertTo-EnhancedHTMLFragment -TableCssID APPVTABLE `
                                            -DivCssID APPVDIV `
                                            -DivCssClass WHATEVER `
                                            -TableCssClass TABLEWHATEVER `
                                            -EvenRowCssClass 'even'`
                                            -OddRowCssClass 'odd'`
                                            -As Table -Properties * `
                                            -PreContent '<h2> AppVPackages: <h2/>'  |
                                           
            Out-String # Collapse an array of strings to 1 single string
    
    
    $frag2 = Get-CMApplications | Select-Object localizeddisplayname | 
             ConvertTo-EnhancedHTMLFragment -TableCssID APPLICATIONTABLE `
                                            -DivCssID APPLICATIONDIV `
                                            -DivCssClass WHATEVER `
                                            -TableCssClass TABLEWHATEVER `
                                            -EvenRowCssClass 'even'`
                                            -OddRowCssClass 'odd'`
                                            -As Table -Properties * `
                                            -PreContent '<h2> Applications<h2/>' |
                                           
            Out-String
    
    
    
    
    
    
    ConvertTo-EnhancedHTML -HTMLFragments $frag1,$frag2`
                           -title "SCCM Software report" `
                           -PreContent "<h1>Softare Report</h1>"`
                           -PostContent "<br /><br />Retrieved $(Get-Date)" `
                           -CssStyleSheet $css |
    
    out-file C:\report.html
    



    Jan Hoedt

    Monday, November 30, 2015 6:31 PM
  • Start with a primer on how PowerShell works with objects. For example:

    Windows IT Pro - PowerShell: Objects and Output


    -- Bill Stewart [Bill_Stewart]

    Monday, November 30, 2015 7:44 PM
    Moderator