다음을 통해 공유


ConvertTo-Xml

Creates an XML-based representation of an object.

구문

Default (기본값)

ConvertTo-Xml
    [-Depth <Int32>]
    [-InputObject] <PSObject>
    [-NoTypeInformation]
    [-As <String>]
    [<CommonParameters>]

Description

The ConvertTo-Xml cmdlet creates an XML-based representation of one or more .NET 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, in-memory XML document that includes representations of all the objects.

This cmdlet is similar to Export-Clixml except that Export-Clixml stores the resulting XML in a Common Language Infrastructure (CLI) file that can be reimported as objects with Import-Clixml. ConvertTo-Xml returns an in-memory representation of an XML document, so you can continue to process it in PowerShell. ConvertTo-Xml doesn't have an option to convert objects to CLI XML.

예제

Example 1: Convert a date to XML

Get-Date | ConvertTo-Xml

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

Example 2: Convert processes to XML

ConvertTo-Xml -As "Document" -InputObject (Get-Process) -Depth 3

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

매개 변수

-As

Determines the output format. The acceptable values for this parameter are:

  • String - Returns a single string.
  • Stream - Returns an array of strings.
  • Document - Returns an XmlDocument object.

The default value is Document.

매개 변수 속성

형식:String
Default value:None
허용되는 값:Stream, String, Document
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-Depth

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.

매개 변수 속성

형식:Int32
Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-InputObject

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.

매개 변수 속성

형식:PSObject
Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:0
필수:True
파이프라인의 값:True
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

-NoTypeInformation

Omits the Type attribute from the object nodes.

매개 변수 속성

형식:SwitchParameter
Default value:None
와일드카드 지원:False
DontShow:False

매개 변수 집합

(All)
Position:Named
필수:False
파이프라인의 값:False
속성 이름별 파이프라인의 값:False
나머지 인수의 값:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

입력

PSObject

You can pipe any object to this cmdlet

출력

String

When you use the As parameter and set the value to string, this cmdlet returns the XML as a string. When the value is stream, this cmdlet returns an array of strings.

XmlDocument

By default, this cmdlet returns an XML document.