0

I call a Powershell script from a c# program, getting back an collection of PSObjects as a result of pipeline.Invoke(). As a part of the PS script, an email is sent using Net.Mail.SmtpClient. However, sending an email takes some time, so I moved the email sending code into a script block that is executed using Start-Jon -ScriptBlock... And here the problem started: email is not sent. When I execute a script from a command line, it sends an email.

What can be the reason?

3
  • Any output or error messages ? Commented Feb 14, 2013 at 8:35
  • Not really. pipeline return no errors, script works (in a sense that it returns processed data back to the c# program. Just email is not sent. Commented Feb 14, 2013 at 9:05
  • Have you tried running a "dumber" script i.e. one that just writes the arguments/parameters you are passing to a file instead of emailing. Commented Feb 14, 2013 at 9:45

1 Answer 1

1

Actually, after adding Wait-Job to the code (making it synchronous) it worked again. I think that I got it. I was calling runspace.Close() at the end of my code that terminated the host so the Powershell background job had no chance to be executed. So I looking in the wrong place, unfortunately.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.