.Net Tools for PowerShell

There are a lot of cmdlet’s available in PS, but sometimes you need a bit of extra salt and pepper.

That’s when .NET Framework Classes can give you the solution.

This article .NET Scripting using PowerShell explains how you can use .Net Classes in Powershell.

But it’s not so easy to get hold of all the available .Net Assemblies, Classes, Members (Methods & Properties) etc.

You have to be aware of the DLL structure in order know what Classes to instantiate and what methods to call.

So we need some Tools to help us out.

One of the well-known is the IL Spy which will give all inside information needed Smile

Let’s look at this simple example

image

In PowerShell you can use the Get-Date command.

image

But you can use as well the equivalent .Net System.DateTime Class from the mscorlib Assembly.

image

And in the DateTime Class the Today() property object.

But of course there are a huge number of Classes you can start digging in Smile

More interesting articles of the master chef himself

http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/11/why-use-net-framework-classes-from-within-powershell.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/11/use-powershell-to-work-with-the-net-framework-classes.aspx

Another nice Tool is the .Net Reference Explorer

image

This one is superb as well .Net Reflector 6.0

image

It has some nice add-ons as well like Powershell syntax translation from C#, or the Intergrated Assembly Graph

image

And many more, this version can’t be download anymore, but there is a hack available to do so Smile

GAC Registration

If you build your own Assemblies and wants to use the in PowerShell, you need to install the assembly into Global Assembly Cache (GAC).

Use correct gacutil.exe for your version of .NET framework

Or use this PS code

Add-Type -AssemblyName "System.EnterpriseServices"
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("YourAssembly.dll")

Not at all needed to register in the GAC ?

See here on how to overcome the GAC registration.

Not even needed to have the Assembly DLL distributed as a file ?

See here on how to avoid the Assembly DLL distribution.

Enjoy !

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: