Introduction to Scripting COM Objects with PowerShell
ComObject, or plain COM, increases the range of PowerShell activities. One way of looking at COM objects is as a mechanism for PowerShell to launch programs, for example, mimicking the RUN command. Another way of looking at
ComObjects is performing the role previously undertaken by VBScript.
For both those tasks, scripting with COM objects gives you a rich selection of options. The bonus of using PowerShell rather than VBScript is that you need fewer commands.
The secret of manipulating COM objects is starting with the command:
New-Object -COM. What comes next depends on which type of object you need. Here are examples of creating, then manipulating
ComObject with $variables:-
#ComObject to launch the Internet Explorer application. Clear-Host $ie =
New-Object -ComObject InternetExplorer.Application; $ie.visible=$true
Note 4: Incidentally, -Com and -ComObject appear to be interchangeable.
Guy Recommends: A Free Trial of the Network Performance Monitor
(NPM)
SolarWinds'
Network Performance Monitor
will help you discover what's happening on your network. This
utility will also guide you through troubleshooting; the dashboard will
indicate whether the root cause is a broken link, faulty equipment or
resource overload.
Perhaps the NPM's best feature is the way it suggests solutions to network
problems. Its second best feature is the ability to monitor the health of
individual VMware virtual machines. If you are interested in
troubleshooting, and creating network maps, then I recommend that you try
Solarwinds NPM now.
Let us investigate the properties of the
-Com object. At first, Get-Member appears not work, even help seems unsupportive. Fortunately, all that is missing is the
name of the -Com object that you wish to research. For example:
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft's operating systems. Fortunately, SolarWinds
have created a
Free WMI Monitor so that you can discover these gems of performance
information, and thus improve your PowerShell scripts.
Take the guess work out of which WMI counters to use when scripting the
operating system, Active Directory, or Exchange Server. Give this WMI monitor a
try - it's free.
The ComObject family of commands add important capabilities to PowerShell. For example, creating network objects means that you don't have to revert to VBScript when you need to map network drives. Another way
of looking at the -ComObject command is as a PowerShell method of accessing the Run dialog box programmatically.
If you like this page then please share it with your friends
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is
most useful for PowerShell scripting.
SolarWinds
have produced this
Free WMI Monitor to take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.