ConvertTo-CliXml
将对象转换为 CliXml 格式的字符串。
语法
Default (默认值)
ConvertTo-CliXml
[-InputObject] <PSObject>
[-Depth <Int32>]
[<CommonParameters>]
说明
ConvertTo-CliXml cmdlet 将对象转换为格式化为公共语言基础结构 (CLI) XML 的字符串。 此命令类似于 Export-Clixml,但它不会写入文件。 而是输出字符串。
PowerShell 7.5-preview.4 中引入了此 cmdlet。
示例
示例 1 - 将进程对象转换为 CliXml 并返回
此示例显示将进程对象转换为 CliXml 和返回的结果。 首先,当前进程存储在变量 $process中。 进程对象的 pstypenames 属性显示对象的类型 System.Diagnostics.Process。 下一个命令显示进程对象中每种类型的成员的计数。
$process = Get-Process -Id $PID
$process.pstypenames
System.Diagnostics.Process
System.ComponentModel.Component
System.MarshalByRefObject
System.Object
$process | Get-Member | Group-Object MemberType | Select-Object Name, Count
Name Count
---- -----
AliasProperty 7
CodeProperty 1
Property 52
NoteProperty 1
ScriptProperty 8
PropertySet 2
Method 19
Event 4
$xml = $process | ConvertTo-CliXml
$fromXML = ConvertFrom-CliXml $xml
$fromXML.pstypenames
Deserialized.System.Diagnostics.Process
Deserialized.System.ComponentModel.Component
Deserialized.System.MarshalByRefObject
Deserialized.System.Object
$fromXML | Get-Member | Group-Object MemberType | Select-Object Name, Count
Name Count
---- -----
Property 46
NoteProperty 17
PropertySet 2
Method 2
接下来,进程对象将转换为 CliXml 并返回。 新对象的类型以 Deserialized为前缀。 新对象中的成员计数与原始对象不同。
参数
-Depth
指定 XML 表示形式中包含多少个包含对象的级别。 默认值为 2。
参数属性
| 类型: | Int32 |
| 默认值: | 2 |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-InputObject
要转换为 CliXml 格式的字符串的对象。
参数属性
| 类型: | PSObject |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。