< Back

Import-Clixml

Tue Jan 29, 2019 10:22 pm

NAME Import-Clixml



SYNOPSIS

Imports a CLIXML file and creates corresponding objects in Windows PowerShell.





SYNTAX

Import-Clixml [-First <UInt64>] [-IncludeTotalCount] -LiteralPath <String[]> [-Skip <UInt64>] [<CommonParameters>]



Import-Clixml [-Path] <String[]> [-First <UInt64>] [-IncludeTotalCount] [-Skip <UInt64>] [<CommonParameters>]





DESCRIPTION

The Import-CliXml cmdlet imports a CLIXML file with data that represents Microsoft .NET Framework objects and creates the objects in Windows

PowerShell.



A valuable use of Import-CliXml is to import credentials and secure strings that have been exported as secure XML by running the Export-Clixml

cmdlet. For an example of how to do this, see Example 2.





PARAMETERS

-First <UInt64>

Gets only the specified number of objects. Enter the number of objects to get.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-IncludeTotalCount [<SwitchParameter>]

Reports the total number of objects in the data set (an integer) followed by the selected objects. If the cmdlet cannot 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 could not 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.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-LiteralPath <String[]>

Specifies the XML files. 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.



Required? true

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-Path <String[]>

Specifies the XML files.



Required? true

Position? 0

Default value None

Accept pipeline input? True (ByPropertyName, ByValue)

Accept wildcard characters? false



-Skip <UInt64>

Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip.



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, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

System.String

You can pipe a string that contains a path to Import-Clixml .





OUTPUTS

PSObject

Import-Clixml returns objects that have been deserialized from the stored XML files.





NOTES





* When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".



*



Example 1: Import a serialized file and recreate an object



PS C:\\>Get-Process | Export-Clixml pi.xml

PS C:\\>$Processes = Import-Clixml pi.xml



This command uses the Export-Clixml cmdlet to save a serialized copy of the process information returned by Get-Process. It then uses

Import-Clixml to retrieve the contents of the serialized file and re-create an object that is stored in the $Processes variable.

Example 2: Import a secure credential object



PS C:\\>$Credxmlpath = Join-Path (Split-Path $Profile) TestScript.ps1.credential

PS C:\\>$Credential | Export-CliXml $Credxmlpath

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

APIhttp://msdn.microsoft.com/library/windows/apps/xaml/hh464970.aspx. 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, you 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.



RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/?LinkId=821813

Use PowerShell to Pass Credentials to Legacy Systems

http://blogs.technet.com/b/heyscripting ... stems.aspx

Securely Store Credentials on Disk http://www.powershellcookbook.com/recip ... ls-on-disk

Export-Clixml