Run C # code using Powershell

Is it possible to write C # script code and execute it using PowerShell?

Instead of running C # using the command line tools provided by Visual Studio, I want to write a C # script using Notepad ++ and execute the code using PowerShell.

+7
c # powershell
source share
1 answer

Using C # code in PowerShell

"The client is like scripting languages ​​because it allows them to write their own code without having to run the compiler or copy new executables to their production machines, which usually require a more complex approval process than deploying a script file or even execute commands in the shell.

So, it would be great if the existing C # code could be reused inside PowerShell without having to implement it as a Cmdlet. "

$Assem = ( ...add referenced assemblies here... ) $Source = @" ...add C# source code here... "@ Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp 

A complete example is provided in the blog article.

https://blogs.technet.microsoft.com/stefan_gossner/2010/05/07/using-csharp-c-code-in-powershell-scripts/

+8
source share

All Articles