ConvertFrom-CliXml
將 CliXML 格式的字串轉換為自訂的 PSObject。
語法
Default (預設值)
ConvertFrom-CliXml
[-InputObject] <String>
[<CommonParameters>]
Description
ConvertFrom-CliXml該指令小程式將格式化為通用語言基礎設施(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 |
| 預設值: | 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。