ConvertFrom-CliXml

将 CliXml 格式的字符串转换为自定义 PSObject

语法

Default (默认值)

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
默认值: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

输入

String

输出

Object