Export to an XML file, any text string or PowerShell object can be represented in XML.

      Export-Clixml [-path] string -inputObject psobject
         [-depth int] [-force] [-encoding string]
            [-noClobber] [-whatIf] [-confirm] [CommonParameters]

   -Path string
        The XML file to be created.

   -inputObject psobject
        The object to be converted. {may be piped}
        A variable containing the object(s) 
        or a command/expression that returns the object(s).

   -depth int 
        How many levels of contained objects to include in the XML
        A depth of 1 will include Object > properties
        a depth of 2 will include Object > properties >Objects >Properties
        and so on *

       Override restrictions that prevent the command from succeeding, apart
       from security settings. e.g. Force will override a files read-only attribute,
       but will attempt to reset the read-only attribute when the command completes.

       Do not overwrite the contents of an existing file.
       The default is to overwrite without warning.

    -encoding string
       The type of encoding for the target file. Valid values are:
       ASCII, UTF8, UTF7, UTF32, Unicode , BigEndianUnicode, Default, and OEM.
       In PowerShell 7 and above the default changed from Unicode (UTF-16LE) to UTF8(NoBOM).

       Describe what would happen if you executed the command without actually
       executing the command.

       Prompt for confirmation before executing the command.

* If the object being exported has a type-specific depth (specified in the *.types.psxml file), then that depth will be used unless you specify the -Depth parameter.

Under Windows, Export-Clixml creates Unicode UTF-16LE - files by default.
This can be configured via the $PSDefaultParameterValues preference variable.
Under PowerShell Core edition, the encoding defaults to BOM-less UTF-8


Create an XML file that represents the string, "This text will become XML"

PS C:> "This text will become XML" | export-clixml c:\SimpleDemo.xml

Use Get-Acl to retrieve an object containg the ACLs (security descriptors) for a file, and pipe the result into an XML file.

PS C:> get-acl C:\ss64.txt | export-clixml -Path E:\ss64_acl.xml

Retrieve the ACL object from a saved XML file and store in the variable $my_acl:

PS C:> $my_acl = import-clixml E:\ss64_acl.xml

"Beware the man of one book" ~ St. Thomas Aquinas

Related PowerShell Cmdlets

import-clixml - Import a clixml file and rebuild the PS object.
export-csv - Export to Comma Separated Values (spreadsheet).
convertTo-Html - Convert the input into an HTML table.

Copyright © 1999-2024 SS64.com
Some rights reserved