Using COM Objects to Say "Hi!"

If you have ever written scripts using VBScript, you probably know COM objects which are DLLs and work like command libraries. You can use COM objects in PowerShell, too. Simply use New-Object and the parameter -COMObject to instantiate the COM library you need.

For example, on XP and above, the COM library SAPI.SpVoice makes your computer speak to you:

$sam = New-Object -comObject SAPI.SpVoice
$sam.Speak('How are you doing, dude?')
$sam.Speak((Get-Date))

If you'd like to know what COM objects live on your computer, look them up! They are all registered in your Windows registry. However, only a fraction of the listed COM libraries are really useful:

Dir registry::HKEY_CLASSES_ROOT\CLSID -include ProgID -recurse | Foreach-Object { $_.GetValue("")}

Posted Dec 03 2008, 08:00 AM by ps1

Comments

Joe Pruitt wrote Listen To Twitter With The PoshMouth PowerShell Service!
on 02-26-2009 5:16 PM

Listen To Twitter With The PoshMouth PowerShell Service!

Aleksandar wrote re: Using COM Objects to Say "Hi!"
on 02-27-2009 1:36 AM
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.