para 'powershell' eu encontrei entrada de blog:
$MaximumHistoryCount = 1KB
if (!(Test-Path ~\PowerShell -PathType Container))
{ New-Item ~\PowerShell -ItemType Directory
}
function bye
{ Get-History -Count 1KB |Export-CSV ~\PowerShell\history.csv
exit
}
if (Test-path ~\PowerShell\History.csv)
{ Import-CSV ~\PowerShell\History.csv |Add-History
}
então você tem que terminar a sessão com "bye" (em vez de "sair" ou fechar a janela através do botão "x").