PowerShell Export-CliXml Cmdlet

PowerShell Export as XMLWindows PowerShell Export-CliXml

Don’t use Export-CliXml, use ConvertTo-Html instead!

Question: OK; what is the point of Export-CliXml?

Answer: To store objects until you need them again; in which case, you call for the sister cmdlet: Import-CliXml.

PowerShell Import and Export-CliXml Topics

 ♣

Export-CliXml Example

In this example I employ Invoke-Item solely to check  that the xml file has been created as expected.

$File = "D:\PShell\ProcUnique.xml"
Get-Process | Export-Clixml $File
Invoke-Item $File

Note: See more about Invoke-Item

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

Export-CliXml – Test with Import-CliXml

Scenario: Let us suppose we are troubleshooting services that are running after we have made a configuration change. 

# PowerShell Export-CliXml Example
$File ="D:\PShell\RunningService.xml"
Get-Service | Where {$_.Status -eq "Running" -And $_.CanStop -eq $false} `
| Export-CliXml $File
Import-CliXml $File

Note 1: Observe the classic Export –> Import combination.

Learning About Export-Clixml’s Syntax

Clear-Host
Get-Help Export-CliXml -Full

Note 2: Userful parameters include -NoClobber, which means don’t over-ride the file.  This parameter is useful if you want the output file to be read-only.

Summary of PowerShell’s Export-CliXml

In truth I have yet to find a killer reason to use Export-CliXml.  I still prefer ConvertTo-Html

If you like this page then please share it with your friends

 


See more Microsoft PowerShell tasks:

PowerShell Home   • Shell Application   • New-Object   • PowerShell Add Printer   • PowerShell -com

PowerShell Logon Script  • Map Network Drive  • PowerShell Create Shortcut  • Free CSV Import Tool

Invoke-Expression   • Invoke-Command   • Invoke-Item   • PowerShell Expression v Command Mode

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.