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/
Marc wittmann
source share