共用方式為


ConvertFrom-CliXml

將 CliXml 格式的字串轉換為自訂 PSObject

語法

ConvertFrom-CliXml
                [-InputObject] <String>
                [<CommonParameters>]

Description

Cmdlet 會將 ConvertFrom-CliXml 格式化為 Common Language Infrastructure (CLI) XML 的字串轉換成自定義 PSObject。 此命令類似於 Import-Clixml,但不會從檔案讀取。 相反地,它會接受字串作為輸入。

新還原串行化的物件不是實時物件。 它們是串行化時物件的快照集。 還原串行化的物件包含屬性,但沒有方法。 pstypenames 屬性包含前面加上 Deserialized的原始類型名稱。

此 Cmdlet 是在 PowerShell 7.5-preview.4 中引進的。

範例

範例 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

輸入

輸出