Import-Clixml

Import a CLIXML file and create corresponding objects within PowerShell.

Syntax
      Import-Clixml { [-path] | -literalpath } string[]
         [-IncludeTotalCount] [-Skip UInt64] [-First UInt64] [CommonParameters]

Key
   -Path string[]
       The path to the XML files {may be piped}

   -LiteralPath path
       The path to the XML file to import.
       Unlike -Path, the value of the -LiteralPath parameter is used exactly as it is typed.
       If the path includes escape characters, enclose it in single quotation marks. 

   -First
       Get only the specified number of objects. Enter the number of objects to get.

   -IncludeTotalCount
       Report the total number of objects in the data set followed by the selected objects.
       If the cmdlet can’t determine the total count, it displays Unknown total count.

       The integer has an Accuracy property that indicates the reliability of the total count value.
       The value of Accuracy ranges from 0.0 to 1.0 where 0.0 means that the cmdlet couldn’t count the
       objects, 1.0 means that the count is exact, and a value between 0.0 and 1.0 indicates an increasingly reliable estimate.

   -Skip
       Ignore the specified number of objects and then get the remaining objects.
       Enter the number of objects to skip.

Import-Clixml imports a Common Language Infrastructure (CLI) XML file with data that represents Microsoft .NET Framework objects and creates the PowerShell objects.

A valuable use of Import-Clixml on Windows computers is to import credentials and secure strings that were exported as secure XML using Export-Clixml.

The Export-Clixml cmdlet encrypts credential objects by using the Windows Data Protection API. The encryption ensures that only your user account 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. Export-Clixml only exports encrypted credentials on Windows. On non-Windows operating systems such as macOS and Linux, credentials are exported in plain text.

Import-Clixml uses the byte-order-mark (BOM) to detect the encoding format of the file. If the file has no BOM, it assumes the encoding is UTF8.

Examples

Save a serialized copy of process information to an XML file, then use Import-Clixml to retrieve the contents of the file and recreate as an object stored in the $processes variable.

PS C:> get-process | export-clixml proc.xml
$processes = import-clixml proc.xml

Export and then Import a secure credential object. Given a credential previously stored in the $Credential variable (by running Get-Credential), you can run Export-Clixml to save the credential to disk:

# define filename
$Credxmlpath = Join-Path (Split-Path $Profile) TestScript.ps1.credential
# export credential to filename
$Credential | Export-Clixml $Credxmlpath

# define filename (again)
$Credxmlpath = Join-Path (Split-Path $Profile) TestScript.ps1.credential
# import credential from filename
$Credential = Import-Clixml $Credxmlpath


“The real danger is the gradual erosion of individual liberties through the automation, integration, and interconnection of many small, separate record-keeping systems, each of which alone may seem innocuous, even benevolent, and wholly justifiable” ~ U.S. Privacy Protection Study Commission, 1977

Related PowerShell Cmdlets:

export-clixml - Produce a clixml representation of PowerShell objects.
export-csv - Export to Comma Separated Values (spreadsheet).
convertTo-Html - Convert the input into an HTML table.


 
Copyright © 1999-2022 SS64.com
Some rights reserved