26 February, 2013
0 Comments
1 category
If you want to create an object based on the C# code in a *.cs file, by using PowerShell 3.0 you can use the following C# and PowerShell code:
Create a folder "C:\Temp"
C# MyClass.cs file
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; namespace MyNameSpace { public class MyClass { public void MyFunction() { Console.WriteLine("Hello from MyNameSpace.MyClass.MyFunction."); } } }
PowerShell Execute_MyNamespace_MyClass_MyFunction.ps1
Add-Type -Path "C:\Temp\MyClass.cs" $labeler = New-Object MyNameSpace.MyClass $labeler.MyFunction() pause
Execute
Tags: C#PowerShell
Category: Uncategorized