Export (0) Print
Expand All
Expand Minimize

ConvertTo-Xml

Updated: December 3, 2014

Applies To: Windows PowerShell 4.0

ConvertTo-Xml

Creates an XML-based representation of an object.

Syntax

Parameter Set: Default
ConvertTo-Xml [-InputObject] <PSObject> [-As <String> ] [-Depth <Int32> ] [-NoTypeInformation] [ <CommonParameters>]




Detailed Description

The ConvertTo-Xml cmdlet creates an XML-based representation of one or more Microsoft .NET Framework objects. To use this cmdlet, pipe one or more objects to the cmdlet, or use the InputObject parameter to specify the object.

When you pipe multiple objects to ConvertTo-XML or use the InputObject parameter to submit multiple objects, ConvertTo-XML returns a single XML document that includes representations of all of the objects.

This cmdlet is similar to Export-Clixml except that Export-Clixml stores the resulting XML in a file. ConvertTo-XML returns the XML, so you can continue to process it in Windows PowerShell.

Parameters

-As<String>

Determines the output format. Valid values are:

-- String: Returns a single string.

-- Stream: Returns an array of strings.

-- Document: Returns an XmlDocument object.

The default is Document.


Aliases

none

Required?

false

Position?

named

Default Value

Document

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Depth<Int32>

Specifies how many levels of contained objects are included in the XML representation. The default value is 1.

For example, if the object's properties also contain objects, to save an XML representation of the properties of the contained objects, you must specify a depth of 2.

The default value can be overridden for the object type in the Types.ps1xml files. For more information, see about_Types.ps1xml.


Aliases

none

Required?

false

Position?

named

Default Value

1

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InputObject<PSObject>

Specifies the object to be converted. Enter a variable that contains the objects, or type a command or expression that gets the objects. You can also pipe objects to ConvertTo-XML.


Aliases

none

Required?

true

Position?

1

Default Value

None

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

true

-NoTypeInformation

Omits the Type attribute from the object nodes.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.Management.Automation.PSObject

    You can pipe any object to ConvertTo-XML.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • System.String or System.Xml.XmlDocument

    The value of the As parameter determines the type of object that ConvertTo-XML returns.


Examples

-------------------------- EXAMPLE 1 --------------------------

This command converts the current date (a DateTime object) to XML.


PS C:\> get-date | convertto-xml

-------------------------- EXAMPLE 2 --------------------------

This command converts the process objects that represent all of the processes on the computer into an XML document. The objects are expanded to a depth of three levels.


PS C:\> convertto-xml -as Document -inputObject (get-process) -depth 3

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft