ConvertFrom-CliXml
将 CliXml 格式的字符串转换为自定义 PSObject。
语法
ConvertFrom-CliXml
[-InputObject] <String>
[<CommonParameters>]
说明
该 ConvertFrom-CliXml
cmdlet 将格式化为公共语言基础结构 (CLI) XML 的字符串转换为自定义 PSObject。 此命令类似于 Import-Clixml
,但它不会从文件读取。 而是采用字符串作为输入。
新反序列化的对象不是实时对象。 它们是序列化时对象的快照。 反序列化的对象包括属性,但没有方法。
PSTypeNames 属性包含前缀为 Deserialized
..
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
前缀。 新对象中的成员计数与原始对象不同。
参数
-InputObject
包含要转换的 CliXml 格式字符串的对象。
类型: | String |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |