ConvertTo-Xml
Creates an XML-based representation of an object.
语法
Default (默认值)
ConvertTo-Xml
[-InputObject] <PSObject>
[-Depth <Int32>]
[-NoTypeInformation]
[-As <String>]
[<CommonParameters>]
说明
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 PowerShell.
示例
Example 1: Convert a date to XML
PS C:\> Get-Date | ConvertTo-Xml
This command converts the current date (a DateTime object) to XML.
Example 2: Convert processes to XML
PS C:\> ConvertTo-Xml -As "Document" -InputObject (Get-Process) -Depth 3
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.
参数
-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 |
默认值: | None |
接受的值: | Stream, String, Document |
支持通配符: | False |
不显示: | 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 instance, 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 |
默认值: | None |
支持通配符: | False |
不显示: | 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 |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | 0 |
必需: | True |
来自管道的值: | True |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-NoTypeInformation
Omits the Type attribute from the object nodes.
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | 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 ConvertTo-XML.
输出
System.String or System.Xml.XmlDocument
The value of the As parameter determines the type of object that ConvertTo-XML returns.