PowerShell Logo Small

Export-Clixml



This is the built-in help made by Microsoft for the command 'Export-Clixml', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates an XML-based representation of an object or objects and stores it in a file.

SYNTAX


Export-Clixml [-Path] <String> [-Depth [<Int32>]] [-Encoding {Unicode | UTF7 | UTF8 | ASCII | UTF32 | BigEndianUnicode | Default | OEM}] [-Force] [-InformationAction
{SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-NoClobber] -InputObject <PSObject> [-Confirm] [-WhatIf]
[<CommonParameters>]
Export-Clixml [-Depth [<Int32>]] [-Encoding {Unicode | UTF7 | UTF8 | ASCII | UTF32 | BigEndianUnicode | Default | OEM}] [-Force] [-InformationAction {SilentlyContinue | Stop
| Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-NoClobber] -InputObject <PSObject> -LiteralPath <String> [-Confirm] [-WhatIf]
[<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Export-CliXml cmdlet creates an XML-based representation of an object or objects and stores it in a file. You can then use the Import-CliXml cmdlet to re-create the
saved object based on the contents of that file.


This cmdlet is similar to ConvertTo-XML, except that Export-CliXml stores the resulting XML in a file. ConvertTo-XML returns the XML, so you can continue to process it in
Windows PowerShell.


A valuable use of Export-CliXml is to export credentials and secure strings securely as XML. For an example of how to do this, see Example 3 in this topic.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293956
Use PowerShell to Pass Credentials to Legacy Systems
Securely Store Credentials on Disk
ConvertTo-Html
ConvertTo-Xml
Export-Csv
Import-Clixml

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>"This is a test" | export-clixml sample.xml



This command creates an XML file that stores a representation of the string, "This is a test".










-------------------------- EXAMPLE 2 --------------------------

PS C:\>get-acl C:\test.txt | export-clixml -Path fileacl.xml
PS C:\>$fileacl = import-clixml fileacl.xml



This example shows how to export an object to an XML file and then create an object by importing the XML from the file.

The first command uses the Get-ACL cmdlet to get the security descriptor of the Test.txt file. It uses a pipeline operator to pass the security descriptor to Export-Clixml,
which stores an XML-based representation of the object in a file named FileACL.xml.

The second command uses the Import-Clixml cmdlet to create an object from the XML in the FileACL.xml file. Then, it saves the object in the $FileAcl variable.










-------------------------- EXAMPLE 3 --------------------------

PS C:\>$credxmlpath = Join-Path (Split-Path $profile) TestScript.ps1.credential
PS C:\>$credential | Export-CliXml $credPath
PS C:\>$credxmlpath = Join-Path (Split-Path $profile) TestScript.ps1.credential
PS C:\>$credential = Import-CliXml $credxmlpath



The Export-CliXml cmdlet encrypts credential objects by using the Windows Data Protection API. This ensures that only your user account can decrypt the contents of the
credential object.

In this example, given a credential that you’ve stored in the $credential variable by running the Get-Credential cmdlet, you can run the Export-CliXml cmdlet to save the
credential to disk.In the example, the file in which the credential is stored is represented by TestScript.ps1.credential. Replace TestScript with the name of the script
with which you are loading the credential.

In the second command, pipe the credential object to Export-CliXml, and save it to the path, $credxmlpath, that you specified in the first command.





To import the credential automatically into your script, run the final two commands. This time, you are running Import-CliXml to import the secured credential object into
your script. This eliminates the risk of exposing plain-text passwords in your script.