Write-Output of XML value has type format like "System.Xml.X..."

@

@lways

Hi,

I want to output some value using Write-Output or Write-Host along with some
comments.

After reading the xml file and while executing the write-output command, its
not printing the value, its printing the variable
type along with xml structure not the value :(

Please let me know how to print the correct output.

See below the example for details.


---------------------------------------------------------------------------------------------------------------------------
Variable.xml
---------------------------------------------------------------------------------------------------------------------------
<variable>
<test>
<branchname>
<port2666>testvalue_win11.2.$hfno</port2666>
<\branchname>
<\test>
<\variable>


---------------------------------------------------------------------------------------------------------------------------
Test.ps1
---------------------------------------------------------------------------------------------------------------------------

$hfno="005"
[xml]$xmlcontent=get-content .\Variable.xml

Write-Output "Some Comments along with
$xmlcontent.variable.test.branchname.port2666 "
---------------------------------------------------------------------------------------------------------------------------
Output
---------------------------------------------------------------------------------------------------------------------------
Actual ouput : Some Comments along with
System.Xml.XmlDocument.variable.test.branchname.port2666

Expected ouput : Some Comments along with testvalue_win11.2.005
---------------------------------------------------------------------------------------------------------------------------


Regards,
Harsha
 

My Computer

C

Chris Dent

You must use a Sub-Expression if you expect PS to expand properties in a
string:

Write-Output "Some Comments along with
$($xmlcontent.variable.test.branchname.port2666)"


HTH

Chris

@lways wrote:

> Hi,
>
> I want to output some value using Write-Output or Write-Host along with some
> comments.
>
> After reading the xml file and while executing the write-output command, its
> not printing the value, its printing the variable
> type along with xml structure not the value :(
>
> Please let me know how to print the correct output.
>
> See below the example for details.
>
>
> ---------------------------------------------------------------------------------------------------------------------------
> Variable.xml
> ---------------------------------------------------------------------------------------------------------------------------
> <variable>
> <test>
> <branchname>
> <port2666>testvalue_win11.2.$hfno</port2666>
> <\branchname>
> <\test>
> <\variable>
>
>
> ---------------------------------------------------------------------------------------------------------------------------
> Test.ps1
> ---------------------------------------------------------------------------------------------------------------------------
>
> $hfno="005"
> [xml]$xmlcontent=get-content .\Variable.xml
>
> Write-Output "Some Comments along with
> $xmlcontent.variable.test.branchname.port2666 "
> ---------------------------------------------------------------------------------------------------------------------------
> Output
> ---------------------------------------------------------------------------------------------------------------------------
> Actual ouput : Some Comments along with
> System.Xml.XmlDocument.variable.test.branchname.port2666
>
> Expected ouput : Some Comments along with testvalue_win11.2.005
> ---------------------------------------------------------------------------------------------------------------------------
>
>
> Regards,
> Harsha
>
 

My Computer

Top