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

beta
  • 5,324
  • 15
  • 57
  • 99

0 Answers0