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>
        <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"/>

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


Dorman, J
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 ($ -eq 10193) 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,


Use an XPath expression to select an agent with a specific ID:

[xml]$xml = Get-Content '.\UserMgntCfg.xml'

$id = 10003
$agent = $xml.SelectSingleNode("//ACDAgent[@id='$id']")

extract the queue IDs and penalties to an array:

$queues = $agent.queues.queue | % { $; $_.penalty }

then join it all together:

'{0};{1};{2}' -f $, $id, ($queues -join ';')

Need Your Help

HTML to PDF with Wicked PDF and letter-spacing issues

wkhtmltopdf pdfkit wicked-pdf

Using both 0.79 and 0.7.2 the PDF generated looks slightly different than my original HTML. Adding the show_as_html flag presents it as expected however the inline-styles are being handled differe...

AngularJS Unknown provider: dataProvider <- data <- PageCtrl

javascript angularjs

I have seen the other answers and so far nothing has helped me. I get this error with the following code in a file:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.