Powershell: Convert XML to String

2019-03-22 16:38发布

问题:

I am searching for a way to convert a XML-Object to string.

Is there a way like $xml.toString() in Powershell?

回答1:

You are probably looking for OuterXml.

$xml.OuterXml should give you what you want.



回答2:

How are you creating the XML object?

Typically, if you want an XML string from an object, you'd use:

$object | ConvertTo-Xml -As String