SharpeRAD / Cake.Powershell

Powershell addin for Cake
http://cakebuild.net
MIT License
83 stars 36 forks source link

how to call multi-lines powershell code? #10

Closed constructor-igor closed 8 years ago

constructor-igor commented 8 years ago

Hi,

I want to send email from cake with help of powershell script. In other script I use function SendEmail (see below). In cake script I found next "single-line" way:

StartPowershellScript("$Outlook = New-Object -ComObject Outlook.Application\n$Mail = $Outlook.CreateItem(0)\n$Mail.To = 'igor@test.com'\n$Mail.Subject = 'report'\n$Mail.Body = 'body'\n$Mail.Attachments.Add('file.html')\n$Mail.Send()");

But I have a 2 problems:

  1. How can I write the commands in multi-lines?
  2. Powershell informs that it cannot find file file.html. But the file placed near cake script.
function SendEmail([String] $to, [String] $subject, [String] $body, [String] $attachment)
{
    $Outlook = New-Object -ComObject Outlook.Application
    $Mail = $Outlook.CreateItem(0)
    $Mail.To = $to #"boss@company.com"
    $Mail.Subject = $subject
    $Mail.Body = $body
    $Mail.Attachments.Add($attachment) 
    $Mail.Send()
}
SharpeRAD commented 8 years ago

This isn't an issue with the addin as aliases are called from a cake file which is C# code, so your really asking how do I write multi-line text in C#...

Why don't you save it as a powershell file and call that using the "StartPowershellFile" alias?