# Help Parsing XML file

**URL:** <https://forums.powershell.org/t/help-parsing-xml-file/8482>\
**Category:** PowerShell Help\
**Created:** [April 21, 2017, 2:47pm UTC](https://forums.powershell.org/t/help-parsing-xml-file/8482 "2017-04-21T14:47:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris3460](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@chris3460](https://forums.powershell.org/u/chris3460)\
**Post date:** [April 21, 2017, 2:47pm UTC](https://forums.powershell.org/t/help-parsing-xml-file/8482/1 "2017-04-21T14:47:17Z")

</div>

Wondering if someone can assist in my first attempt to parse an xml file.

The file is formatted as (apologies for the welfare xml format - I can’t figure out how to get it to show up:

-factory  
-customization  
-userServices  
-add key=“Imaging.Viewer.Remote1” assembly=“OpenContent.Platform.Imaging.dll” class=“OpenContent.Imaging.Services.ViewerASMXProxy”  
-parameter name=“initializationKey” class=“string” value=“Imaging.Viewer.Remote1” –  
-parameter name=“url” class=“string” value=“[https://hostname1.domain.net/WebSite/Viewer/ViewerASMX.asmx](https://hostname1.domain.net/WebSite/Viewer/ViewerASMX.asmx)” –  
–add  
–userServices  
–customization  
–factory

My end goal is to make a list of all the URL’s listed on the URL class line. The “parameter name=“url” class=“string” value=” is used in other nodes as places within the customization node as well, so I need to limit it to just the one’s on a key -like “_Imaging.Viewer.Remote_”

I’m not all that fluent in PowerShell or XML, but here’s what I’ve tried so far:

```
[xml]$ServiceFact = gc "C:\Logs\Internal Testing\ServiceFactoryConfiguration.xml"
$userServices = $ServiceFact.factory.customization.userservices.add.name | % {$_.value -like "*imaging.viewer.remote*" }
$userservices
```

This returns a list filled with just the word “False” repeated over and over. I thought I’d comment out the pipe section of it, but that just gives me the word “Add” over and over again. I’m probably missing something, but thinking I need to conquer this portion of it, then narrow down for each result to find the URL. Any thoughts?

---

<div class="post-metadata">

**Author:** ![chris3460](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@chris3460](https://forums.powershell.org/u/chris3460)\
**Post date:** [April 21, 2017, 3:18pm UTC](https://forums.powershell.org/t/help-parsing-xml-file/8482/2 "2017-04-21T15:18:22Z")

</div>

Okay, I’ve gotten a little further… I’ve found that

```
[xml]$ServiceFact = gc "C:\\Logs\ServiceFactoryConfiguration.xml"
$userServices = $ServiceFact.factory.customization.userservices.add 
$userservices
```

returns a list organized by key, assembly, class, and parameter. If I change it to:

```
[xml]$ServiceFact = gc "C:\\Logs\ServiceFactoryConfiguration.xml"
$userServices = $ServiceFact.factory.customization.userservices.add | % {$_.key -like "*imaging.viewer.remote*" }
$userservices
```

I get true/false statements saying whether or not this value matches… How do I create a variable for a key like “_imaging.viewer.remote_” and a parameter like “_URL_” together?

---

<div class="post-metadata">

**Author:** ![chris3460](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@chris3460](https://forums.powershell.org/u/chris3460)\
**Post date:** [April 21, 2017, 4:10pm UTC](https://forums.powershell.org/t/help-parsing-xml-file/8482/3 "2017-04-21T16:10:49Z")

</div>

Almost there… I’ve now got the childnodes showing the name, class, and value… I can actually see the URL I want to show…

```
$FormatEnumerationLimit = 80
[xml]$ServiceFact = gc "C:\Logs\ServiceFactoryConfiguration.xml"
$renderParam = $ServiceFact.factory.customization.userservices.add | where-object {$_.key -like "*imaging.viewer.remote*" }# | select-object parameter 
$renderparam | select-object -ExpandProperty childnodes
```

Last part is showing just the URL value. The one thing that’s constant in this value among all of our customers is the _website/viewer/viewerasmx_ so I’m trying to figure out how to filter for that… I attempted this:

```
$FormatEnumerationLimit = 80
[xml]$ServiceFact = gc "C:\Logs\ServiceFactoryConfiguration.xml"
$renderParam = $ServiceFact.factory.customization.userservices.add | where-object {$_.key -like "*imaging.viewer.remote*" }# | select-object parameter 
$RenderURL = $renderparam | select-object -ExpandProperty childnodes
$renderURL | select-object value -like "*webaccess/viewer/viewerasmx*"
```

but it just gave me this error:

Select-Object : A parameter cannot be found that matches parameter name ‘like’.  
At line:7 char:34

- $renderURL | select-object value -like "_webaccess/viewer/viewerasmx_ …
- 

```
                             ~~~~~

```

  - CategoryInfo : InvalidArgument: (🙂 [Select-Object], ParameterBindingException
  - FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

---

<div class="post-metadata">

**Author:** ![chris3460](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@chris3460](https://forums.powershell.org/u/chris3460)\
**Post date:** [April 21, 2017, 9:18pm UTC](https://forums.powershell.org/t/help-parsing-xml-file/8482/4 "2017-04-21T21:18:37Z")

</div>

Got it!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/help-parsing-xml-file/8482/5 "2024-05-16T20:38:52Z")

</div>


