Query XML data with Powershell in exMon

Created by: Gunnar Steinn Magnússon

In this article, you will learn how to query XML data with Powershell in exMon. This can, for example, be used to monitor changes in files, find suspect nodes or compare against another data source.

In this example, we will use data from books.xml, a list of books with attributes where we will find all books priced higher than $10.00

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
   ... more books ...
</catalog>

Follow these steps to create the query

  1. Create a Query in exMon Administrator
  2. Choose "PowerShell" as a Data Provider
  3. Enter the following PowerShell script
    [xml]$xml = Get-Content "C:\temp\books.xml"

    $xml.SelectNodes('/catalog/book') | where {[decimal]$_.price -gt 10 } | select id, author, title, price
  4. Configure email settings and schedule as normally

Example output from the test:

Gunnar is the author of this solution article.