title: Powershell SelectSingleNode on a child node
body: <p>I'm using Powershell to install an SSIS Project and create a Environment for it.  I am reading the project parameters from the Project.Params XML file to create the environment variables &amp; their values.  I am able to use the following code snippet to read the parameters &amp; their values, but I'd like to use SelectSingleNode instead of the second foreach loop. My XPath skills are not up to it.
  Here's the working code:</p>
  
  <pre><code># load the Params file into memory
  [xml]$ParamsDoc = Get-Content -Path $ParamsFilePath
  
  # for each parameter in the Params file, add an environment variable if it doesn't already exist
  foreach ($Param in $ParamsDoc.Parameters.Parameter)
  {
      $ParamName = $Param.Name
  
      # use the value in the Params file as the default value for the environment variable
      foreach ($Prop in $Param.Properties.Property)
      {
          if ($Prop.Name -eq 'value')
          {
              $ParamValue = $Prop.InnerText
              break
          }
      }
      AddEnvironmentVariableIfMissing $ParamName $ParamValue
  }
  </code></pre>
  
  <p>AddEnvironmentVariableIfMissing is a separate function I've written.  Now, here's the code that doesn't work:</p>
  
  <pre><code># load the Params file into memory
  [xml]$ParamsDoc = Get-Content $ParamsFilePath
  
  $nsMgr = New-Object System.Xml.XmlNamespaceManager($ParamsDoc.NameTable)
  $nsMgr.AddNamespace("SSIS", $ParamsDoc.DocumentElement.NamespaceURI)
  
  foreach ($Param in $ParamsDoc.Parameters.Parameter)
  {
      $ParamName = $Param.Name
  
      # NONE of these work!
      $ParamValue = $Param.Properties.SelectSingleNode("SSIS:Property[@Name='Value']",$nsMgr)
      $ParamValue = $Param.Properties.SelectSingleNode("Name[.='Value']",$nsMgr)
      $ParamValue = $Param.Properties.SelectSingleNode("SSIS:Property/Name[.='Value']",$nsMgr)
      $ParamValue = $Param.Properties.Property.SelectSingleNode("Name[.='Value']",$nsMgr)
      $ParamValue = $Param.SelectSingleNode("SSIS:Properties/SSIS:Property[@Name='Value']",$nsMgr)
      $ParamValue = $Param.SelectSingleNode("SSIS:Properties/SSIS:Property/Name[.='Value']",$nsMgr)
      $ParamValue = $Param.SelectSingleNode("SSIS:Property[@Name='Value']",$nsMgr)
      $ParamValue = $Param.SelectSingleNode("SSIS:Property/Name[.='Value']",$nsMgr)
  
      AddEnvironmentVariableIfMissing $ParamName $ParamValue
  }
  </code></pre>
  
  <p>What is the correct XPath syntax to get the child node with Name = 'Value'?</p>
  
  <p>Here's a sample of an SSIS Project.params file</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;SSIS:Parameters xmlns:SSIS="www.microsoft.com/SqlServer/SSIS"&gt;
    &lt;SSIS:Parameter
      SSIS:Name="Client"&gt;
      &lt;SSIS:Properties&gt;
        &lt;SSIS:Property
          SSIS:Name="ID"&gt;{144b0266-9e94-4821-bb68-f020436d5df5}&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="CreationName"&gt;&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="Description"&gt;&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="IncludeInDebugDump"&gt;0&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="Required"&gt;0&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="Sensitive"&gt;0&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="Value"&gt;sampleclient&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="DataType"&gt;18&lt;/SSIS:Property&gt;
      &lt;/SSIS:Properties&gt;
    &lt;/SSIS:Parameter&gt;
    &lt;SSIS:Parameter
      SSIS:Name="MSSQLServer"&gt;
      &lt;SSIS:Properties&gt;
        &lt;SSIS:Property
          SSIS:Name="ID"&gt;{b4e6c5e1-ef85-4df3-b2dc-db37971d081d}&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="CreationName"&gt;&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="Description"&gt;&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="IncludeInDebugDump"&gt;0&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="Required"&gt;0&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="Sensitive"&gt;0&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="Value"&gt;MSSQLSERVER&lt;/SSIS:Property&gt;
        &lt;SSIS:Property
          SSIS:Name="DataType"&gt;18&lt;/SSIS:Property&gt;
      &lt;/SSIS:Properties&gt;
    &lt;/SSIS:Parameter&gt;
  &lt;/SSIS:Parameters&gt;
  </code></pre>