Powershell: how to suppress output of Select-Xml?

340 Views Asked by At

I assigned XML file contents to a variable $config and then used another variable $market to store the output of XPath query:

$config = Get-Content -Path "C:\files\configs\config.xml" -raw
$market = (select-xml -Content $config -xpath /process-config/input/filePattern/marketCode).node.'#text'

Then I add the following line:

write-host this is $market

And the output is this:

PS C:\ps_scripts> .\xmltest.ps1

this is citigroup_ams 
#text
-----
 citigroup_ams

My desired output would be:

PS C:\ps_scripts> .\xmltest.ps1

    this is citigroup_ams 

I attempted to add | Out-Null at the end of the 2nd line but in this case only the output of Write-Host cmdlet was suppressed. Is there any other way to suppress the output of Select-Xml?

1

There are 1 best solutions below

2
On

You're probably looking for something like this :

$config = [xml]@'
  <process-config> 
    <input> 
      <filePattern> 
        <marketCode>citigroup_ams</marketCode>
      </filePattern>
    </input>  
  </process-config> 
'@
$market = $config.SelectNodes("/process-config/input/filePattern/marketCode/text()").Value
Write-Host "this is" $market

Output : this is citigroup_ams