CLIXML

The Export-Clixml cmdlet can be used to serialize objects to file, which can then be easily deserialized with Import-Clixml. Serialization is the process of exporting objects to a file or data format with its specific type information. It is similar to the techniques we learned earlier, except that it keeps the type information with it:

#Defining file for export
$exportedFile = 'C: empexportedProcesses.xml'

#Exporting services and strong into variable
Get-Process| Tee-Object -Variable exportedProcesses | Export-Clixml $exportedFile

#Showing variable
$exportedProcesses

#Importing services
$importedProcesses = Import-Clixml $exportedFile

#Comparing objects - no difference should be visible
Compare-Object -ReferenceObject $exportedProcesses -DifferenceObject $importedProcesses -Property ProcessName, Id

#Starting another process - Notepad.exe
Notepad.exe

#Comparing objects with current process list
Compare-Object -ReferenceObject $exportedProcesses -DifferenceObject $(Get-Process) -Property ProcessName, Id

In the preceding example, the current process list is compared with a saved one. This might be useful when comparing configurations with each other. Storing a CLIXML also comes in very handy when storing class instances to file. Classes are described later in this chapter. The good thing about working with CLIXML is that you don't need to take care of the type, as the cmdlets will include the serialized type automatically.

..................Content has been hidden....................

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