0

I am calling a C# DLL from my Powershell script with the following lines of code.

Add-Type -Path "PATH_TO_DLL";
$MyClass = New-Object -TypeName MyClass;
$MyClass.MyMethod();

The MyMethod() method has the following signature:

public async Task MyMethod()

The MyMethod() code outputs stuff by using System.Console.WriteLine(). When I execute the powershell code via the powershell command line, I can see this output on the command line. However, if I want to output this to a separate log file by using Start-Transcript ... and Stop-Transcript, I only get a VoidTaskResult that looks as can be seen here: https://pastebin.com/xK76W0h2

I already tried the solutions described in the following threads, but they did not yield the desired result for me. None of the log output that is written by the C# application with System.Console.WriteLine() is shown or logged. Why?

How to capture process output asynchronously in powershell?

Getting result of .Net object asynchronous method in powershell

2
  • "[...] but they did not yield the desired result for me. Why?" - well, what kind of result did they yield? What actually happened when you launched the script as a child process? Commented Mar 3, 2022 at 10:48
  • I amended the OP. Commented Mar 4, 2022 at 11:07

0

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.