0

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 empty Commented Oct 21, 2014 at 12:40
  • Sorry I was just editing post to include XML file I just need syntax to query what displayname value = and set to a variable Commented Oct 21, 2014 at 12:42

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

100% Works, thank you so much for your time and help.
0

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" 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.