Reputation: 392
I'm looking for the code required to email myself the return I receive when performing PowerShell scripts. I know I'd have to use a Send-MailMessage
, but I'm stuck with the PowerShell to use the return I receive as the email body.
My powershell script is a mixture of powershell and sqlcmd.
For example:
echo "Selecting Count from ExampleTable"
sqlcmd -i D:\IRDW\Tools\script_to_Count_ExampleTable.txt
Start-Sleep 2
Return in powershell:
124794 (1 rows affected)
Upvotes: 0
Views: 43
Reputation: 1263
Another suggestion:
$body = Invoke-Command -ScriptBlock {
echo 'test'
'sqlcmd ...'
Start-Sleep -Seconds 2
} | Out-String
or
$body = Start-Job -ScriptBlock {
echo 'test'
'sqlcmd ...'
Start-Sleep -Seconds 2
} | Wait-Job | Receive-Job | Out-String
Upvotes: 1