Tuesday, July 24, 2012

PowerShell: show Property Bag data

Of course this is not rocket science but  thought this might still be useful when developing or troubleshooting a Management Pack with PowerShell modules:

Your script body usually looks like this:

  # Always use the param statement to access parameters
  # Get access to the scripting API
  $API = new-object -comObject "MOM.ScriptAPI"
  # Create the property bag
  $BAG = $API.CreatePropertyBag()
  # Do your magic script stuff here
  # Populate the property bag with data

The “problem” here is that if you run your script directly in PowerShell for troubleshooting you’d always get “System.__ComObject”.

After adding the following line to your script you’ll get the XML data that has been added to the property bag:

Not a big thing but helpful at all…

All information is provided "as is" without any warranty! Try in lab before. Handle with care in production.

1 comment:

  1. Great Post! It's very nice to read this info from someone that actually knows what they are talking about. http://bwbaker.com