powershell system.object.tostring() problem

Guido Jeuken 71 Reputation points
2020-08-23T06:43:24.507+00:00

Hello everybody,
i have to write a powershell script to backup an azure blog storage.
I want to send the result as an email.
But I don't get the result, but "System.Object []" as the mail body.
The script works perfect, I'm able to backup my azure blob storage to onPrem, only the status mail does not work as excepted.

Here are the relevant parts of the script.
$azlog= d:\azure_backup\azcopy.exe sync $source $dest --recursive
Send-MailMessage -To $rec -From $smtpFrom -Subject $messageSubject -encoding ASCII -body $azlog.ToString() -smtpserver $smtpServer

Many thanks,

Guido

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,446 questions
0 comments No comments
{count} votes

Accepted answer
  1. Showndarya Madhavan 336 Reputation points
    2020-08-23T07:07:42.96+00:00

    Hi @Guido Jeuken ,

    Can you try this?

    Send-MailMessage -To $rec -From $smtpFrom -Subject $messageSubject -encoding ASCII -body ($azlog | Out-String) -smtpserver $smtpServer

    Reference: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-string

    Hope this helps!


0 additional answers

Sort by: Most helpful