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” –
–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?
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?
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