Using Powershell to do discovery

One of the things I really like about OpsMgr is the ability for it to manage script files from the management pack all the way to the managed node.  This is commonly done with VBscript for things like discovery and monitoring WMI, and for command scripts for things like agent tasks. 
 
Console tasks and things like powershell scripts tend to require that the file be accessible on the machine running the console or on the agent, respectively.
 
If you play with the <Files> tags a little, though, there’s no reason you can’t push Powershell scripts to agents.  You can even publish data back to OpsMgr.  Of course, you have to have Powershell available on every target that will run the script….
 
Linked is a management pack that I worked on for a friend that instantiates a particular service class on every machine, but sets a property equal to true or false depending on whether the service is actually on that machine.  This is done in the WMI WQL query that looks for %SQL%.
 
It does a second-stage discovery targeting the class itself setting another property.  The cool thing (to me) about this secondary discovery is that it’s a powershell script rather than a VBscript, and the script is entirely contained in the MP.  No messing with local files.
 
Finally, there’s a group population discovery that sticks all computers that *do* contain the service into a particular computer group.  I was pretty psyched to discover that the command executer module didn’t puke on the $var variable notation of Powershell.  I expected it to get confused with the macro that expands things like $MPElement..$ and $Target/Property…$ notations but it didn’t.
 
Also note that in Powershell, the AddProperty method parameters have to be wrapped in parentheses; not true for VBScript.
 
I played around with PropertyBags as well and they seem to work just fine, too.
 
Very cool.
 
 

http://cid-f2cbe6bae5bb51e1.skydrive.live.com/embedrowdetail.aspx/Public/MyMP.zip

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s