Eggins.com
Powershell, .Net, Visual Studio, Team Foundation Server, Windows Communication Foundation

Load an assembly in Powershell Pt 2

Yesterday I posted on adding an assembly to Powershell. You should be aware that if you load an assembly from the command line, it will only be loaded during that session. If you exit the command line, and run the Powershell command line again, you will not have that assembly loaded.

If you have an assembly that you often use during your command line sessions, you should add the load command for that assembly to your profile.ps1 file. For example, include the following command line in your profile.ps1 file to load the System.Web assembly during every Powershell command line session.
    [Reflection.Assembly]::LoadFrom("C:\WINDOWS\Assembly\Gac\System.Web" `
    + "\1.0.5000.0__b03f5f7f11d50a3a\System.Web.dll")

This can be very handy for having command line access to your own custom business objects. Lets say you have a business object that exposes an interface to add a user to your web application. You would be able to load that assembly, create the object instance, and add a user to your web applications all from the command line or a script. Having command line access to your own business objects opens up a whole new world of opportunities.


Posted May 29 2007, 09:58 PM by David
Filed under:

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Copyright eggins.com, 1998 - 2008
Powered by Community Server (Non-Commercial Edition), by Telligent Systems