Поделиться через


ConvertTo-CliXml

Converts an object to a CliXml-formatted string.

Синтаксис

Default (по умолчанию)

ConvertTo-CliXml
    [-InputObject] <PSObject>
    [-Depth <Int32>]
    [<CommonParameters>]

Описание

The ConvertTo-CliXml cmdlet converts objects to strings that are formatted as Common Language Infrastructure (CLI) XML. This command is similar to Export-Clixml, but it doesn't write to a file. Instead, it outputs a string.

This cmdlet was introduced in PowerShell 7.5-preview.4.

Примеры

Example 1 - Convert a process object to CliXml and back

This example shows the result of converting a process object to CliXml and back. First, the current process is stored in the variable $process. The pstypenames property of the process object shows that the object is of type System.Diagnostics.Process. The next command displays the count for each type of member in the process object.

$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

Next, the process object is converted to CliXml and back. The type of the new object is prefixed with Deserialized. The count of members in the new object is different from the original object.

Параметры

-Depth

Specifies how many levels of contained objects are included in the XML representation. The default values is 2.

Свойства параметра

Тип:Int32
Default value:2
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-InputObject

The object to be converted to a CliXml-formatted string.

Свойства параметра

Тип:PSObject
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:0
Обязательно:True
Значение из конвейера:True
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Входные данные

PSObject

Выходные данные

String