locked
Powershell report by mail? RRS feed

  • Question

  • Hi,

    I'd like to send the output of a Powershell to myself by mail.

    This is what I'm using:

    $AppVpackages = Invoke-Command -ScriptBlock { Get-AppvClientPackage * -all } -ComputerName Myserver
    $Body = $AppVpackages
    $FromAddress = "mymailaddress"
    $ToAddress = "mymailaddress"
    $MessageSubject = "RDS Report"
    $SendingServer = "mymailserver"
    $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject,$body
    $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
    $SMTPClient.Send($SMTPMessage)

    The $AppVPackages gives correct result:

    PSComputerName       : mycomputer
    RunspaceId           : e83788ec-0738-4ee3-bcfc-1f61043a9924
    PackageId            : ae237bab-0844-450b-a075-aed1817c6498
    VersionId            : 394fa10e-429e-43f1-9855-74a1da1a7fdf
    Name                 : AppVPackage
    ...

    But the output I receive in the mail is not ok:

    Microsoft.AppV.AppvClientPowerShell.AppvClientPackage Microsoft.AppV.AppvClientPowerShell.AppvClientPackage Microsoft.AppV.AppvClientPowerShell.AppvClientPackage Microsoft.AppV.AppvClientPowerShell.AppvClientPackage Microsoft.AppV.AppvClientPowerShell.AppvClientPackage Microsoft.AppV.AppvClientPowerShell.AppvClientPackage Microsoft.AppV.AppvClientPowerShell.AppvClientPackage

    What could be wrong with my script?

    Note: I'd like to add several Powershell-scripts as a report, can I add them to $Body (f.e. $Body = $AppVPackages,$NumberOfUsers etc)?

    Thanks for your input!

    J.


    Jan Hoedt

    Wednesday, September 9, 2015 9:26 AM

Answers

  • $AppVpackages = Invoke-Command -ScriptBlock { Get-AppvClientPackage * -all } -ComputerName Myserver |
       Format-List | Out-String


    \_(ツ)_/


    • Edited by jrv Wednesday, September 9, 2015 9:48 AM
    • Marked as answer by janhoedt Monday, September 21, 2015 11:59 AM
    Wednesday, September 9, 2015 9:47 AM