I want to use Powershell to write some utilities, leveraging our own .NET components to handle the actual work. This is in place of writing a small console app to tie the calls together. My question is where I would find a good source of documentation or tutorial material to help me fast track this?


Do you need info about simply using .Net assemblies in powershell, or are you looking for info on writing assemblies that are more powershell friendly?

+8  A: 

If you want to load an assembly into your PowerShell session, you can use reflection and load the assembly.


After you load your assembly, you can call static methods and create new instances of a class.

A good tutorial can be found here.

Both books mentioned by EBGreen are excellent. The PowerShell Cookbook is very task oriented and PowerShell in Action is a great description of the language, its focus and useability. PowerShell in Action is one of my favorite books. :)

Steven Murawski
+1: for the nice tutorial link
Sung Meister
@Sung Thanks, I'm actually working on a series about using .NET from PowerShell on my blog -
Steven Murawski
-1: for the broken tutorial link
Hans Malherbe
+3  A: 

The link that Steven posted is a good example. I don't know of any extensive tutorial. Both the Windows Powershell Cookbook and Windows Powershell In Action have good chapters on the subject. Also, look at the ::LoadFromFile method of the System.Reflection.Assembly class in case your in-house assemblies are not loaded in the GAC.


Thanks guys. At the moment I'm looking to use .NET assemblies not written with powershell in mind. I wrote a library that manages a set of data for an application. It allows persisting/loading of data in both database and file. While I am hacking at data in the database I wanted to create a one-click method of backing up the data from the database to a file that I can run regularly as a safety net. I'll see if I can get it going with the info you've provided.

Steve Crane

Got the library loaded but it seems that the way it and the libraries it depends on are written is going to make accessing it from powershell tricky so I'll leave it for now, but I will still get into using powershell more.

Steve Crane
I'm having the same problem I believe. Loading assemblies which themselves also have dependencies on other assemblies. For some reason this is not working for me.