Trying to embed C# code in Powershell v1


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.

My csharp code is:

In my Powershell code, I just put

at the begging of this code and

at the end of the code but it don’t work. I’m using Powershell version 1. Please help convert my C# code.


Try this:

It’s the powershell equivalent code.

Your code for using in add-type (only powershell V2 or V3, for V1 you have to create a DLL and use [Reflection.Assembly]::LoadFile("c:\myddl.dll") )


Trying to embed C# code in Powershell v1 by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply