Use PowerShell
Real Admins Script
Real Admins Script
Since PowerShell is built on .NET, there is a AppDomain (I’ll go into more detail in a later post) which has a lot of information about the .NET environment (what assemblies are loaded, etc..).
One feature that the AppDomain has is to store globally accessible name/value pairs. Normally, variables in PowerShell should handle most of your “in-process” storage needs, but for the times that they don’t, you have your AppDomain.
To access the AppDomain object, you can use the static property CurrentDomain on the System.AppDomain class.
(NOTE: Though I usually refer use the fully qualified namespace, PowerShell does allow you to skip the “System” portion of the namespace. I’m using the full namespace for clarity on the blog, but when typing on the command line, it is easier to skip that.)
PS C:\> [system.appdomain]::CurrentDomain
To save a name/value pair to your AppDomain, you can use the SetData method.
PS C:\> [system.appdomain]::CurrentDomain.SetData(‘ThisIsMyNameOrKey’, (‘This’,'Can’,'Be’,'Any’,'Object’,'Or’,'Collection’) )
Any object or collection can be saved in the AppDomain, and you are not limited to just one.
Accessing those values is just as easy, using the GetData method.
PS C:\> [system.appdomain]::CurrentDomain.GetData(‘ThisIsMyNameOrKey’)
This
Can
Be
Any
Object
Or
Collection
And there we have our collection back.
PSMDTAG:.Net AppDomain
March 25, 2009 - 10:10 am
Great – I was just workig my way through the Posh implementation of AppDomain when I stumbled on this blog entry. Thanks any help is greatly appreciated. PowerShell may be Great but it is also very BIG! It will take an army to gt it all sorted out.
March 25, 2009 - 4:06 pm
PowerShell is big, and getting bigger with V2. PowerShellCommunity.org has some great forums for questions and answers.. Watch for a detailed exploration of AppDomain in PowerShell soon!
March 25, 2009 - 5:32 pm
I hope we can explore dynamic assembly loading and unloading. It looks like this can be done with a separate AppDomain but so far no one seems to have tricked it out. I am gong to do the whole excercise in C# to get a better understanding of this process then see what can be done. I think Snover has promised to remedy this for V2 but haven’t looked to see if it has been done yet.
Good luck and see you at the org I suspect.
March 25, 2009 - 7:18 pm
Thanks for the direction suggestion. Let’s see were that goes.
March 26, 2009 - 2:24 pm
I have a hint for loading a second domain ionto PoSH. It can be loaded and unloaded and can contain assemblies that will unload with new domain unload. The only issue is that we need to use delegates to successfully call from current domain into new domain. Calling code in alternate domains can be ugly in PoSH but we should be able to launch scripts into the new domain. This could crate a good test harness for testing libraries that need to be recompilied often. This and teh use of “ShadowCopy services.
Keep all this in mind if you are planning a domain special.
GL
April 16, 2009 - 8:58 pm
nice, really nice!
May 28, 2010 - 4:14 pm
good post explain the app domain
http://blog.flair-systems.com/2010/05/c-fastfood-what-appdomain.html