header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Help loading .Net assemblies requested.
Last Post 08 Apr 2008 07:39 PM by kscriss. 10 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
04 Apr 2008 10:10 PM  

 I am referencing the following two articles:

http://blogs.msdn.com/powershell/archive/2006/04/25/583254.aspx

http://www.leeholmes.com/blog/HowDoIEasilyLoadAssembliesWhenLoadWithPartialNameHasBeenDeprecated.aspx 

[System.Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")

[System.Reflection.Assembly]::Load("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

[appdomain]::currentdomain.getassemblies() |ft fullname

Where can I find a list of assemblies I can load using the above mehtod?

kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
04 Apr 2008 10:11 PM  
Or what is the method preferred as we move into the future?
smurawskiUser is Offline
New Member
New Member
Posts:46

--
04 Apr 2008 11:26 PM  
Windows Explorer actually can provide some help here. If you navigate to C:\Windows\Assembly, it will provide a listing of all the .NET assemblies stored there (this is not an exclusive list, especially if you have other .NET software installed), but it can help you find the assemblies and namespaces you are looking for.

That, combined with the MSDN documention will be a starting place.

I'll post more, including some examples, this weekend.
smurawskiUser is Offline
New Member
New Member
Posts:46

--
06 Apr 2008 08:06 PM  
So, as I was looking at various ways to get at assemblies and the types contained, I found that the Powershell Community Extensions has two cmdlets, in addition to a provider for the GAC (Global Assembly Cache). One of the cmdlets (Resolve-Assembly) allows you to search for a partial name and returns any assembly objects that match. You can pipe the result into the Load static method of System.Reflection.Assembly:


resolve-assembly system.windows.forms | ForEach-Object {[void][System.Reflection.Assembly]::Load($_)}


If you want to find the types in that assembly you could pipe it to:

 <br> resolve-assembly system.windows.forms | ForEach-Object {$_.GetTypes()} <br> 


If you don't have access to the Community Extensions, you can enumerate the types in assemblies by using the
by loading them by their file name by using [System.Reflection.Assembly]::LoadFile() and then calling the GetTypes method on the returned Assembly object. As I mentioned in the previous post, a large number of .NET assemblies are stored under the C:\Windows\Assembly folder, other .NET assemblies and applications can be found in other locations (usually the application install directory).

Hope this helps.
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
07 Apr 2008 04:30 PM  
Wow, Thank you very much. I'm multi-tasking right now, so this is going to take a while to digest. That Windows explorer thing is kewl. I'll have to find some spare time to think that second post of your through though.
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
07 Apr 2008 07:02 PM  
I'm using PowerShell 1.0 without the Community Extenstions. I don't think I have a resolve-assembly CMDlet.

I tried the following:

$A=[System.Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
$B = $A.GetType()
$B | GM

but I can't seem get-a-hold-of System.Windows.Forms to do a Get-Member it comes back as a System.RunTime.Type. I'm pretty sure I'll be able to do some cool things once I figure out what I am doing wrong.


smurawskiUser is Offline
New Member
New Member
Posts:46

--
07 Apr 2008 07:40 PM  
Kevin,

Try $a.GetTypes() instead of GetType(). GetType returns a System.RuntimeType, like you mentioned. GetTypes returns a list of all the types that are available in that assembly.
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
07 Apr 2008 10:45 PM  
Thanks the $A.GetTypes() is much better than $A.GetType().

The following code snippet produces a messagebox widget. I can figure out how to see the "MESSAGEBOX" name but what I can't figure out is how to drill into "MESSAGEBOX" to see the things like "SHOW". I am wanting something like GET-MEMBER on "MESSAGEBOX".


$A=[System.Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
$A.gettypes() | Where-Object {$_.Name -like "Message*"}
[system.windows.forms.messagebox]::show("Hello World")
smurawskiUser is Offline
New Member
New Member
Posts:46

--
07 Apr 2008 10:56 PM  
You could call the GetMembers() method on [System.Windows.Forms.Messagebox].


[System.Windows.Forms.Messagebox].GetMembers()


This will return a collection of all the members, properties and methods, that the object has.
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
08 Apr 2008 04:38 PM  

Thanks Steve I'll give you "Mad Props" if I ever blog a how-to on "Widgets with PowerShell and .Net".

http://www.randomhouse.com/wotd/index.pperl?date=20010213
"Mad Props" The Maven's word of the day.

kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
08 Apr 2008 07:39 PM  

As usual /\/\o\/\/  "The PowerShellGuy" has an excellent writeup titled "PowerShell GUI ScripBlock Monitor Script" using  .Net, and Widgets.

 http://thepowershellguy.com/blogs/posh/archive/2007/01/21/powershell-gui-scripblock-monitor-script.aspx 

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer