Mitch
Mitch

Reputation: 118

running c# in a Powershell

I wrote a simple c# program that I would like to run using a Powershell file. I am brand new to PowerShell with no experience with it except for the couple hours I've spent trying to figure out how this is done. The program is a simple console program that should pop up when executed. Thank you for your help

Upvotes: 1

Views: 148

Answers (1)

krystan honour
krystan honour

Reputation: 6783

You can write code in an assembly and then register it with powershell you can do this by using the Add-Type cmdlet as far back as powershell 2.0, the previous version of powershell did this differently.

So say your code in c# is in foo.dll you would use:

Add-Type -Path foo.dll

you can then call methods with syntax like this from your objects.

[MyClass]::MyMethod(10)

there is a good article on how to do this here

Upvotes: 1

Related Questions