Creating Your own Types

Share |

Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell

Did you know that you can compile any .NET source code on the fly and use this to create your own types? Here is an example illustrating how to create a new type from c# code that has both static and dynamic methods:

$source = @'
public class Calculator
public static int Add(int a, int b)
return (a + b);

public int Multiply(int a, int b)
return (a * b);
Add-Type -TypeDefinition $source
$myCalculator = New-Object Calculator

Posted Jun 28 2010, 08:00 AM by ps1
Copyright 2012 All rights reserved.