Create an XML-based representation of one or more PowerShell objects.
Syntax ConvertTo-XML [-InputObject] psobject [-As {String | Stream | Document} ] [-Depth int] [-NoTypeInformation] [CommonParameters] Key -inputObject psobject The objects to represent as XML. A variable that contains the objects or a command/expression that gets the objects. -As string
Format as: a String (returns a single string),a Stream (returns an array of strings) or a Document (returns an XmlDocument) -CssUri Uri
The Uniform Resource Identifier (URI) of the cascading style sheet The CSS URI is included as a style sheet link in the output. -NoTypeInformation
Omit the Type attribute from the object nodes. -Depth int
The number of levels of contained objects to include. The default value is 1.
For example, if an object's properties also contain objects, specify a depth of 2 to include them.
The default value can be overridden in Types.ps1xml
CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.
If you submit multiple objects, such as all of the services on a computer,ConvertTo-Xml will display the properties of the collection / array.
To display the individual objects, use the pipeline operator to pipe the objects to ConvertTo-Xml one at a time.
Export-Clixml is the same as ConvertTo-XML, except that it saves to a file.
Examples
Display the date as XML on the console :
PS C:\> get-date | convertto-xml
Convert 3 levels of the system processes to XML
PS C:\> Get-Process | ConvertTo-xml -depth 3
“If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack” - Winston Churchill
Related PowerShell Cmdlets:
Select-XML - Find text in an XML string or document