Export (0) Print
Expand All
Expand Minimize

Export-Clixml

Export-Clixml

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

Syntax

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

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




Detailed 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.

Parameters

-Depth<Int32>

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.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Encoding<String>

Specifies the type of encoding for the target file. Valid values are ASCII, UTF8, UTF7, UTF32, Unicode, BigEndianUnicode, Default, and OEM. Unicode is the default.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Force

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.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InformationAction<System.Management.Automation.ActionPreference>

The default value can be overridden for the object type in the Types.ps1xml files. For more information, see about_Types.ps1xml.


Aliases

ia

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InformationVariable<System.String>

The default value can be overridden for the object type in the Types.ps1xml files. For more information, see about_Types.ps1xml.


Aliases

iv

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InputObject<PSObject>

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.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

-NoClobber

Ensures that the cmdlet does not overwrite the contents of an existing file. By default, if a file exists in the specified path, Export-Clixml overwrites the file without warning.


Aliases

NoOverwrite

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Path<String>

Specifies the path to the file where the XML representation of the object will be stored.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-LiteralPath<String>

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 is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.


Aliases

PSPath

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.Management.Automation.PSObject

    You can pipe any object to Export-Clixml.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • System.IO.FileInfo

    Export-Clixml creates a file that contains the XML.


Examples

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

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


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

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

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.


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

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

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.


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

Related topics

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft