Using C# Code in PowerShell
"Customer like scripting languages as it allows them to write custom code without a need to run a compiler or to copy new executables to their production machines which usually requires a more complex approval process than deploying a script file or even to execute the commands within a command shell.
So it would be great if the existing C# code could be reused inside PowerShell without a need to implement it as Cmdlet."
$Assem = (
...add referenced assemblies here...
)
$Source = @"
...add C# source code here...
"@
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp
Full example provided in the blog article
https://blogs.technet.microsoft.com/stefan_gossner/2010/05/07/using-csharp-c-code-in-powershell-scripts/