Get-Unique also requires a sorted list and I assume you probably want to preserve execution order. Try this instead:
Get-History -Count 32767 | Group CommandLine | Foreach {$_.Group[0]} |
Export-Clixml "$home\pshist.xml"
This approach uses the Group-Object cmdlet to create unique buckets of commands and then the Foreach-Object block just grabs the first item in each bucket.
BTW if you want all commands saved to a history file I would use the limit value - 32767 - unless that is what you set $MaximumHistoryCount to. :-)
BTW if you want to automatically save this on exit you can do this on 2.0 like so:
Register-EngineEvent PowerShell.Exiting {
Get-History -Count 32767 | Group CommandLine |
Foreach {$_.Group[0]} | Export-CliXml "$home\pshist.xml" } -SupportEvent
Then to restore upon load all you need is:
Import-CliXml "$home\pshist.xml" | Add-History
Keith Hill
2009-09-17 14:17:04