Query XML data with Powershell

The PowerShell Data Provider in exMon can be used to query XML files. This can, for example, be used to monitor changes in files, find suspect nodes or to 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.0

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

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:
example email

exMon Contact Us