Export-Clixml
Creates an XML-based representation of an object or objects and stores it in a file.
Syntax
ByPath (Default)
Export-Clixml
[-Path] <String>
-InputObject <PSObject>
[-Depth <Int32>]
[-Force]
[-NoClobber]
[-Encoding <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ByLiteralPath
Export-Clixml
-LiteralPath <String>
-InputObject <PSObject>
[-Depth <Int32>]
[-Force]
[-NoClobber]
[-Encoding <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Export-Clixml cmdlet creates a Common Language Infrastructure (CLI) XML-based representation
of an object or objects and stores it in a file. You can then use the Import-Clixml cmdlet to
recreate the saved object based on the contents of that file.
For more information about CLI, see Language independence.
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 PowerShell.
A valuable use of Export-Clixml on Windows computers is to export credentials and secure strings
securely as XML. For an example, see Example 3.
Examples
Example 1: Export a string to an XML file
This example creates an XML file that stores in the current directory, a representation of the string This is a test.
"This is a test" | Export-Clixml -Path .\sample.xml
The string This is a test is sent down the pipeline. Export-Clixml uses the Path parameter
to create an XML file named sample.xml in the current directory.
Example 2: Export an object to an XML file
This example shows how to export an object to an XML file and then create an object by importing the XML from the file.
Get-Acl C:\test.txt | Export-Clixml -Path .\FileACL.xml
$fileacl = Import-Clixml -Path .\FileACL.xml
The Get-Acl cmdlet gets the security descriptor of the Test.txt file. It sends the object down
the pipeline to pass the security descriptor to Export-Clixml. The XML-based representation of the
object is stored in a file named FileACL.xml.
The Import-Clixml cmdlet creates an object from the XML in the FileACL.xml file. Then, it saves
the object in the $fileacl variable.
Example 3: Encrypt an exported 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.
Important
Export-Clixml only exports encrypted credentials on Windows. On non-Windows operating systems
such as macOS and Linux, credentials are exported in plain text.
$Credxmlpath = Join-Path (Split-Path $Profile) TestScript.ps1.credential
$Credential | Export-Clixml $Credxmlpath
$Credxmlpath = Join-Path (Split-Path $Profile) TestScript.ps1.credential
$Credential = Import-Clixml $Credxmlpath
The Export-Clixml cmdlet encrypts credential objects by using the Windows Data Protection API.
The encryption ensures that only your user account on only that computer can decrypt the contents of
the credential object. The exported CLIXML file can't be used on a different computer or by a
different user.
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're
loading the credential.
You send the credential object down the pipeline 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. Run
Import-Clixml to import the secured credential object into your script. This import eliminates the
risk of exposing plain-text passwords in your script.
Parameters
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | cf |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Depth
Specifies how many levels of contained objects are included in the XML representation. The default
value is 2.
The default value can be overridden for the object type in the Types.ps1xml files. For more
information, see about_Types.ps1xml.
Parameter properties
| Type: | Int32 |
| Default value: | 2 |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Encoding
Specifies the type of encoding for the target file. The default value is Unicode.
The acceptable values for this parameter are as follows:
- ASCII Uses ASCII (7-bit) character set.
- BigEndianUnicode Uses UTF-16 with the big-endian byte order.
- Default Uses the encoding that corresponds to the system's active code page (usually ANSI).
- OEM Uses the encoding that corresponds to the system's current OEM code page.
- Unicode Uses UTF-16 with the little-endian byte order.
- UTF7 Uses UTF-7.
- UTF8 Uses UTF-8.
- UTF32 Uses UTF-32 with the little-endian byte order.
Parameter properties
| Type: | String |
| Default value: | Unicode |
| Accepted values: | ASCII, BigEndianUnicode, Default, OEM, Unicode, UTF7, UTF8, UTF32 |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Force
Forces the command to run without asking for user confirmation.
Causes the cmdlet to clear the read-only attribute of the output file if necessary. The cmdlet will attempt to reset the read-only attribute when the command completes.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-InputObject
Specifies the object to be converted. Enter a variable that contains the objects, or type a command
or expression that gets the objects. You can also pipe objects to Export-Clixml.
Parameter properties
| Type: | PSObject |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | True |
| Value from pipeline: | True |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-LiteralPath
Specifies the path to the file where the XML representation of the object will be stored. Unlike Path, the value of the LiteralPath parameter is used exactly as it's typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | PSPath |
Parameter sets
ByLiteralPath
| Position: | Named |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-NoClobber
Indicates that the cmdlet doesn't overwrite the contents of an existing file. By default, if a file
exists in the specified path, Export-Clixml overwrites the file without warning.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | NoOverwrite |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Path
Specifies the path to the file where the XML representation of the object will be stored.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
ByPath
| Position: | 0 |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet isn't run.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | wi |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
PSObject
You can pipeline any object to Export-Clixml.
Outputs
FileInfo
Export-Clixml creates a file that contains the XML.