Thursday, 20 August 2015

XML : Parsing XML with Powershell to find a specific ACD agent and list all info for that ACD agent

I have a XML file containing ACD agents for our phone system and need to extract info about a specific agent and get all related info on that agent.

The XML is like this:

  <?xml version="1.0" encoding="UTF-8"?>  <UserMgntConfig version="1.1">    <Agents digits="5">      <ACDAgent createdUserId="40" groupsId="" id="10003" usersId="4">        <name>Smith, J</name>        <IsVoiceMailUser>false</IsVoiceMailUser>        <queues>          <queue dynamic="false" id="6001" penalty="1"/>          <queue dynamic="false" id="6002" penalty="1"/>          <queue dynamic="false" id="6003" penalty="2"/>          <queue dynamic="false" id="6004" penalty="2"/>          <queue dynamic="false" id="6005" penalty="3"/>        </queues>      </ACDAgent>    

Where I give the script input of an ACD id# like id="10003", I need to be able to get output like this (where I get the name/ACD#/queue/penalty/queue/penalty/queue/penalty/queue/penalty/queue/penalty) like this:

  Smith, J;10003;6001;1;6002;1;6003;2;6004;3;6005;3    

or output in order of one parameter per output line. I've get the following so far.

input in PS editor:

  [xml]$agent = Get-Content .\UserMgntCfg.xml  $agent.UserMgntConfig.agents.ACDAgent[0].name  $agent.UserMgntConfig.agents.ACDAgent[0].id  $agent.UserMgntConfig.agents.ACDAgent[0].queues.queue    

output:

  Dorman, J  10003  dynamic        id         penalty  false          6001       1  false          6002       1  false          6003       2  false          6004       2  false          6005       3    

This would work for me but the input is the index of the array [0] but I need to be able to get the results by agent id like [10193] instead. By leaving out the queues/queue nodes I can use...

  | where ($_.id -eq 10193)     

...to get a specific agent but that does not return the queue/queues info which is what I need to know.

I'm new to XML and Powershell but learning. Any ideas will be much help and I will study further to refine the process. The end result is that I need to input a agent and then test several phone systems for that agent to see if the systems are all configured the same. This inquiry is the first step to that end. Thanks in advance for any ideas,

No comments:

Post a Comment