title: How to step through a mix of Powershell and c# code?
body: <p>I have some c# code mixed in with my Powershell script and it's maddening to try and troubleshoot without being able to put break points where the c# code is and psjobs are.</p>
  
  <p>I'm using Powergui as my IDE. If there is a better way to do this, I'm all ears. I've wasted an enormous amount of time not being able to troubleshoot the c# portion as you would in a normal IDE. The c# works fine when ran in a c# IDE.</p>
  
  <p>Thanks</p>
  
  <pre><code>$containerScript = {
      $logfile = "c:\temp\powershell_cSharp.txt";
      try
      {
          "try: " + ([DateTime]::Now.ToString()) | Out-File $logfile -Append;
          $windowFinder = New-Object cSharpNS.CSforPS; # namespace.class
      }
      catch
      {
          "catch: " + ([DateTime]::Now.ToString()) | Out-File $logfile -Append;
          $assemblies = ("System", "System.Data", "System.DirectoryServices", "System.Collections", "System.IO", "System.Windows.Forms", "System.Threading", "System.Runtime.InteropServices", "System.DirectoryServices.AccountManagement", "System.Security.Principal", "System.Drawing");
          #Add-Type -TypeDefinition $windowCheck -ReferencedAssemblies $assemblies -Language CSharp;
          #Add-Type -TypeDefinition $mailAddr -ReferencedAssemblies $assemblies -Language CSharp;
          Add-Type -TypeDefinition $cSharpCode -ReferencedAssemblies $assemblies -Language CSharp; # add the string of c# code
          $windowFinder = New-Object cSharpNS.CSforPS; # namespace.class
      }
  
      $error.Clear();
      "Calling windowFinder.Code() in containerScript_" + ([DateTime]::Now.ToString()) | Out-File $logfile -Append;
      Write-Host "Calling windowFinder.Code() in containerScript";
      $result = $windowFinder.code(); #namespace.class.function
      "result: " + $result + "_" + ([DateTime]::Now.ToString()) | Out-File $logfile -Append;
      "error: " + $error + "_" + ([DateTime]::Now.ToString()) | Out-File $logfile -Append;
      "Finished windowFinder.Code() in containerScript_" + ([DateTime]::Now.ToString()) | Out-File $logfile -Append;
      Write-Host "Finished windowFinder.Code() in containerScript";
  
  }
  
  Start-Job -ScriptBlock $containerScript;
  
  Write-Host "Finished";
  </code></pre>