Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
If you want to call a static function (Shared in Visual Basic) in the .NET Framework, you type in the full name of the class (including the namespaces) followed by double colon (::) and the name of the function you want to call.
The function Load in the Assembly class can be used to load .NET assemblys from the GAC, so if you want to use the .NET Framework, it’s a good start to load the parts of the .NET Framework you need.
[System.Reflection.Assembly]::Load(“System.Windows.Forms, Version=2.0.50727.1433, Culture=neutral, PublicKeyToken=b77a5c561934e089”)
Notice that the string argument that is passed to the Load function is fairly complex. There is a chicken version of Load available where you only have to specify the path to the namespace you want to load. The name of that function is LoadWithPartialName, but it is not recommended that you use that function, because it is obsolete. If you are looking for the parameters that needs to be included in the string passed to the Loadfunction, check the properties window of the assembly in your GAC (usually C:\Windows\assembly).
When this is done, you can access the methods of the classes in System.Windows.Forms. This example will show a message box:
To create instances from classes in any loaded part of .NET Framework, use the New-Object cmdlet.
To use New-Object to create COM objects, just add the -comobject parameter to New-Object. If you have Excel installed, this will load and view it. First type:
$x=New-Object -comobject Excel.Application
Tags: .NET Framework