Reading In An Xml File From PowerShell
The Import-Clixml cmdlet will import an XML file that was saved using Export-Clixml and then rebuilds the Windows PowerShell object for you. For example, suppose you use the GetChildItem cmdlet to retrieve a collection of files found in the folder C:\Scripts; you then use the Export-Clixml cmdlet to save that information as an XML file:

Code:

Get-ChildItem c:\scripts | Export-Clixml c:\scripts\files.xml



Any time you feel like it you can retrieve that data using Import-Clixml; simply call the cmdlet followed by the name of the file to import. For example, this command retrieves the data and stores it in a variable named $A:

Code:

$A = Import-Clixml c:\scripts\files.xml


So what will $A be equal to? It will be equal to the collection of files that were in C:\Scripts at the time you originally ran Get-ChildItem.


The best part is that $A is not simply a collection of string data, but an actual Windows PowerShell object. Try piping $A through the Sort-Objectcmdlet and see what happens:

Code:

$A | Sort-Object length