Changes

Using COM with Windows PowerShell 1.0

34 bytes added, 17:45, 15 May 2009
no edit summary
== Creating COM Object Instances in Windows PowerShell ==
New COM object instances are created within Windows PowerShell using the ''new-object'' cmdlet combined with the ''-comobject'' parameter. This parameter may also be abbreviated to ''-com''. In order to avoid a any ambiguity which may result in a .NET or interop library with the same name being loaded, the ''-strict'' switch is also recommended:
new-object -comobject ''object name'' -strict
== Interacting With COM Objects ==
With the information covered so far in this chapter, it is now possible to begin working with COM objects. Clearly once an instance of an object has been created, it is then possible to begin calling methods and setting properties on the object to make it perform tasks and behave in certain ways. As an example of this in action, we will created create an instance of the ''InternetExplorer.Application'' object, make it visible on the Windows desktop and navigate to a specific URL:
<pre>
</pre>
Now that we have an object instance and a list of methods and properties, it is time to start performing some tasks. For example, to invoke Windows Explorer initialized to a specified folder (in this case C:\tmp):
<pre>
</pre>
Once executed, Notepad should be running and visible, the currently active application , and contain the text which reads "Hello From Windows PowerShell and COM".
== Summary ==
In this chapter we have taken a tour of the basics of using Windows PowerShell in conjunction with the Component Object Model (COM). As with .NET, it should be evident that the availability of COM to the Windows PowerShell developer considerably enhances range of options for performing tasks within the contexts context of Windows. Entire books could, and indeed have, been written on COM, so take what you learned in this chapter, grap a COM book from the library and unleash the power that is available to you as a Windows PowerShell programmer.  <google>BUY_WPS_BOTTOM</google>