Using the Export-Clixml Cmdlet

Saving Data as an XML File

Of course you can save Windows PowerShell output in XML format; what else would you use the Export-Clixml cmdlet for? This simple command uses the Get-Process cmdlet to retrieve information about all the processes running on the computer. That information is then piped to the Export-Clixml cmdlet, which in turn saves the data as an XML file named C:\Scripts\Test.xml:



Get-Process | Export-Clixml c:\scripts\test.xml

The resulting XML file will look something like this:

Windows PowerShell


By default Export-Clixml overwrites any existing copy of C:\Scripts\Test.xml. If you’d prefer not to overwrite Test.xml then simply include the -noclobber parameter in your command:



Get-Process | Export-Clixml c:\scripts\test.xml -noclobber

If you run this command and Test.xml already exists you’ll get back the following error message:



Export-Clixml : File C:\scripts\test.xml already exists and NoClobber was specified.

And, no, the Scripting Guys didn’t come up with the name NoClobber. But we wish we had!

Related Links

Show: