Export-Clixml and Import-Clixml

Export-Clixml creates representations of objects in XML files. Export-Clixml is extremely useful where type information about each property must be preserved.

For example, the following object may be exported using Export-Clixml:

[PSCustomObject]@{ 
    Number  = 1 
    Decimal = 2.3 
    String  = 'Hello world' 
} | Export-Clixml .object.xml 

The resulting XML file shows the type for each of the properties it has just exported:

PS> Get-Content object.xml
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<TN RefId="0">
<T>System.Management.Automation.PSCustomObject</T>
<T>System.Object</T>
</TN>
<MS>
<I32 N="Number">1</I32>
<Db N="Decimal">2.3</Db>
<S N="String">Hello world</S>
</MS>
</Obj>
</Objs>

I32 is a 32-bit integer (Int32). Db is a double-precision floating-point number (double). S is a string.

With this extra information in the file, PowerShell can rebuild the object, including the different types, using Import-Clixml, as follows:

$object = Import-Clixml .object.xml 

Once imported, the value types can be inspected using the GetType method:

PS> $object.Decimal.GetType()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.181.66