Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


May 02, 2008

Q. How do I talk to COM objects or MSAgents in PowerShell?


RSS
Subscribe to Windows IT Pro | See More Tips Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

A. The Microsoft Agents are just COM objects, which means we can hook into them from anything that supports COM, which includes PowerShell. Run the following commands to see Merlin in action:

PS C:\Users\john.SAVILLTECH> $agent = new-object -com Agent.Control.2
PS C:\Users\john.SAVILLTECH> $agent | get-member
TypeName: System.__ComObject#{8563ff20-8ecc-11d1-b9b4-00c04fd97575}

Name MemberType Definition
---- ---------- ----------
ShowDefaultCharacterProperties Method void ShowDefaultCharacterProperties (Variant, Variant)
AudioOutput Property IAgentCtlAudioObjectEx AudioOutput () {get}
Characters Property IAgentCtlCharacters Characters () {get}
CommandsWindow Property IAgentCtlCommandsWindow CommandsWindow () {get}
Connected Property bool Connected () {get} {set}
PropertySheet Property IAgentCtlPropertySheet PropertySheet () {get}
RaiseRequestErrors Property bool RaiseRequestErrors () {get} {set}
SpeechInput Property IAgentCtlSpeechInput SpeechInput () {get}
Suspended Property bool Suspended () {get}


PS C:\Users\john.SAVILLTECH> $null = $agent.connected = 1
PS C:\Users\john.SAVILLTECH> $null = $agent.Characters.Load("Merlin")
PS C:\Users\john.SAVILLTECH> $null = $merlin = $agent.Characters.Character("Merlin")
PS C:\Users\john.SAVILLTECH> $null = $merlin.show()
At this point Merlin is visible and you can drag him around as shown in the figure:
http://www.windowsitpro.com/Common/adforceimages/powershellagent.jpg
You can then have a little fun using the following code:
PS C:\Users\john.SAVILLTECH> $null = $merlin.MoveTo(250, 250, 1)
PS C:\Users\john.SAVILLTECH> $null = $merlin.Play("DoMagic1")
PS C:\Users\john.SAVILLTECH> $null = $merlin.Play("DoMagic2")
PS C:\Users\john.SAVILLTECH> $null = $merlin.Speak("NTFAQ rocks")
PS C:\Users\john.SAVILLTECH> $null = $merlin.think("Complete Guide to Windows Server 2008 is cool")
PS C:\Users\john.SAVILLTECH> $null = $merlin.Hide()
PS C:\Users\john.SAVILLTECH> $merlin = $null
PS C:\Users\john.SAVILLTECH> $agent = $null

You can also pipe information to an agent. For example, the agent could speak out alerts or output. For example, to find and speak the names of all processes with more than 1000 handles, use this command:
PS C:\Users\john.SAVILLTECH> $null = Get-process | Where { $_.handles -gt 1000 } | sort handles | foreach {$merlin.speak($_.Proc
essName + " has " + $_.handles + " handles.")}

See the Figure to see how this works.

http://www.windowsitpro.com/Common/adforceimages/powershellagenhandles.jpg

End of Article



Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
A Simple File Transfer Solution

My small business clients thought FTP was the answer to their file transfer problems, but I surprised them with an even better solution for their data delivery needs. ...

The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

WinInfo Short Takes: 080808 Special Edition

An often irreverent look at some of the week's other news, including a surprising side-trip to Northern Ireland, the 2008 Summer Olympics, Microsoft vs. VMWare, Samsung's lousy SSDs, IBM and Lenovo sitting in a Microsoft-free tree, and much, much more ...


Windows OSs Whitepapers Replay for Exchange: Enterprise Protection and an Affordable Price

Are You Satisfied?

A Preliminary Look at Deployment Plans for Microsoft Windows Vista

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

WinConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

Deploying SharePoint! In-Person Event Series – 8 Cities
Discover best practices and tips for deploying the perfect SharePoint infrastructure. Early Bird Price of $99 through Aug 29th.

Find a new job now on the all new IT Job Hound!
Search jobs, post your resume, and set up job e-mail alerts!

Master SharePoint with 3 eLearning Seminars
Learn how to build a better SharePoint infrastructure and enable powerful collaboration with MVPs Dan Holme and Michael Noel. Register today!

Top Tools for Virtualization Disaster Recovery & Replication
View this web seminar on August 14th to learn about two tools that will result in faster backup and restore with P2V disaster recovery.

SharePointConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

VMworld 2008 - Sign Up Today!
Join your peers on September 15-18 at The Venetian Hotel in Las Vegas as VMware hosts VMworld 2008, the leading Virtualization event.



Entrust Unified Communications Certs
Secure Exchange 2007 and save 20%. Now through Sept. 2008.

When managing just VMware isn’t enough
Plan/Manage/Secure – NetIQ VMware management. Download whitepaper.

Microsoft® Tech•Ed EMEA 2008 IT Professionals
Advance your thinking with new ideas and practical real-world solutions at Microsoft’s FIVE day technical infrastructure conference 3-7 Nov., 2008. Register before 26 September 2008 to save €300.

Order Your Fundamentals CD Today!
Gain an introduction to Exchange, learn server security requirements, and understand how unified communications can play a role in your messaging strategies with this free Exchange CD.

Are You Really Compliant with Software Regulations?
View this web seminar that will help you with compliance best practices and check out a management solution to assure that you won’t be in jeopardy of an audit.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technical Resources Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing