title: Trying to embed C# code in Powershell v1
body: <p>It is my first time to post a question. I am both new to csharp and powershell. Please bear with me if my english is not good at all. 
  I've been trying to convert my csharp code into powershell, but i'm not successful. I tried to research documents about powershell and try each one of them, unfortunately, nothing work for me. My csharp code is working in Visual Studio 2010 but I could not able to embed and work it in Powershell.
  The code below simply catch PID of a taskmanager and write it to notepad with time and date stamp.
  Any help will be greatly appreciated. </p>
  
  <p>My csharp code is:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Text;
  using System.Windows.Forms;
  using System.IO;
  
  namespace GET_TASK
  {
      class Program
      {
          static void Main(string[] args)
          {
  
              var processList = Process.GetProcessesByName("taskmgr");                
  
              foreach (var process in processList)
              {
  
                  string myPath = "C:/powershell/GET_TASK"; //change data path as needed
  
                  FileStream logfile;
                  //log program process
                  logfile = new FileStream(myPath + "/logfile.txt", FileMode.Append, FileAccess.Write); 
  
                  TextWriter oldLog = Console.Out;  
  
                  StreamWriter writelog;
                  writelog = new StreamWriter(logfile);               
  
                  DateTime time = DateTime.Now;
                  string format = "MMM ddd d HH:mm yyyy";
  
                  Console.SetOut(writelog);
  
                  // print out the process id
                  Console.WriteLine("Process Id=" + process.Id + " - " + time.ToString(format));
  
                  Console.SetOut(oldLog);                        
  
                  writelog.Close();
  
                  System.Environment.Exit(0);                               
              }
          }
      }
  }
  </code></pre>
  
  <p>In my Powershell code, I just put</p>
  
  <pre><code>$source = @"
  </code></pre>
  
  <p>at the begging of this code and </p>
  
  <pre><code>Add-Type -TypeDefinition $source
  [GET_TASK.Program]::Main()
  </code></pre>
  
  <p>at the end of the code but it don't work. I'm using Powershell version 1. Please help convert my C# code.</p>