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
Let’s look at this simple example
In PowerShell you can use the Get-Date command.
But you can use as well the equivalent .Net System.DateTime Class from the mscorlib Assembly.
And in the DateTime Class the Today() property object.
But of course there are a huge number of Classes you can start digging in
More interesting articles of the master chef himself
Another nice Tool is the .Net Reference Explorer
This one is superb as well .Net Reflector 6.0
It has some nice add-ons as well like Powershell syntax translation from C#, or the Intergrated Assembly Graph
And many more, this version can’t be download anymore, but there is a hack available to do so
If you build your own Assemblies and wants to use the in PowerShell, you need to install the assembly into Global Assembly Cache (GAC).
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.