I am searching for a way to convert a XML-Object to string.
Is there a way like $xml.toString() in Powershell?
Casting XML Strings to Objects Another way to use PowerShell to parse XML is to convert that XML to objects. The easiest way to do this is with the [xml] type accelerator. By prefixing the variable names with [xml] , PowerShell converts the original plain text XML into objects you can then work with.
PowerShell and Reading XML filesPowerShell provides an easy way to read XML files, manipulate them and finally to save them back to disk without writing a lot of code or knowing XPath. PowerShell does this by providing the user dot notation to signify each node in the XML document.
Use ConvertTo-Csv to Convert XML to CSV in PowerShell You can use the Set-Content cmdlet to write CSV strings to a file. The Set-Content is a string-processing cmdlet that writes new content or replaces the content in a file. The content objects are sent down the pipeline to the ConvertTo-Csv cmdlet.
You are probably looking for OuterXml
.
$xml.OuterXml
should give you what you want.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With