0
votes

Hi I am trying to query below Displayname in XML file using powershell

<DeploymentConfiguration PackageId="dce78f0d-d8d4-4a89-9f5d-c37fbf95ee7a" DisplayName="Beyond-Compare-3-3-8" IgnorableNamespaces="" xmlns="http://schemas.microsoft.com/appv/2010/deploymentconfiguration">

I did try

$Xml = Select-Xml -Path "C:\temp\Beyond-Compare-3-3-8_DeploymentConfig.xml"  -Namespace $Namespace -XPath "DisplayName=" 

I get error

Select-Xml : Cannot validate argument on parameter 'Namespace'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. At line:1 char:191 + ... l" -Namespace $Namespace -XPath "DisplayName=" + ~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Select-Xml], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SelectXmlCommand

2
The error means that your variable $Namespace is either null or emptyPaul
Sorry I was just editing post to include XML file I just need syntax to query what displayname value = and set to a variableZen

2 Answers

1
votes

First of all, your xml is invalid since the node does not get closed. Here is a valid version:

<DeploymentConfiguration PackageId="dce78f0d-d8d4-4a89-9f5d-c37fbf95ee7a" DisplayName="Beyond-Compare-3-3-8" IgnorableNamespaces="" xmlns="http://schemas.microsoft.com/appv/2010/deploymentconfiguration"/>

Now in powershell:

[xml]$xml = Get-content c:\path\xmlFile.xml
$DisplayName= $xml.DeploymentConfiguration.Displayname
0
votes

Using the same approach, you need to register prefix mapped to the default namespace URI, pass the mapping as -Namespace parameter, and use the registered prefix -ns in this example- in your XPath. The XPath expression you tried is also invalid :

$Namespace = @{ ns = 'http://schemas.microsoft.com/appv/2010/deploymentconfiguration'; };
$Xml = Select-Xml -Path "C:\temp\Beyond-Compare-3-3-8_DeploymentConfig.xml"  -Namespace $Namespace -XPath "//ns:DeploymentConfiguration/@DisplayName"