Migrating your auto-complete history to a new Outlook 201X profile with Powershell

In the past with nk2 files, the migration from of Outlook Autocomplete addresses was a lot easier as you just copied the .nk2 file from %AppData%\Roaming\Microsoft\Outlook to the new profile.

As I found out, the steps to migrate the new cache files for Outlook 2010 and greater (Stream_Autocomplete*.*) require some extra steps as I found here:
https://blog.zensoftware.co.uk/2014/05/29/how-to-copy-the-auto-complete-information-to-a-new-outlook-profile/

To speed this up, I have made a powershell script to make this a bit easier. Please note that you will need to do the following first:
– send one message in the new Outlook profile.
– make sure that Outlook is closed.

The code is below:

cls
#Function from https://devblogs.microsoft.com/scripting/hey-scripting-guy-can-i-open-a-file-dialog-box-with-windows-powershell/

Function Get-FileName($initialDirectory)
{  
 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
 Out-Null
 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.initialDirectory = $initialDirectory
 $OpenFileDialog.filter = "All files (*.*)| *.*"
 $OpenFileDialog.ShowDialog() | Out-Null
 $OpenFileDialog.filename
} #end function Get-FileName


$Flag =0
$autocompletecachedir = "$($env:userprofile)\appdata\local\microsoft\outlook\roamcache"
if (get-process outlook -ErrorAction SilentlyContinue) {
"Outlook is currently open. Please close it to proceed."
$Flag = 1
}
If ($flag -eq 0){
$currentacc = get-childitem -path $autocompletecachedir -Filter stream_Autocomplete_*.dat|sort LastWriteTime -desc|select -first 1
If ($currentacc){$flag++}
If ($flag -gt 0) {
"Found the current Autocomplete Cache file:"
$currentaccpath = "$autocompletecachedir\$($currentacc.name)"

"Please find the old Autocomple files to restore."
$Oldaccpath = Get-FileName -initialDirectory "c:\"

if (test-path $oldaccpath){$flag++}
If ($flag -gt 1 ){
	"Found the old Autocomplete file to restore:"
	$Oldacc = get-item "$oldaccpath"
	$Oldacc
	""
    "Backing up current Autocomplete cache..." 
	&robocopy "$autocompletecachedir" "$autocompletecachedir\backup" $($currentacc.name) /njh /njs
	remove-item "$autocompletecachedir\$($currentacc.name)" -force
	"Restoring old Autocomplete cache..."
	&robocopy "$($Oldacc.directoryname)" "$autocompletecachedir" $($Oldacc.name) /njh /njs
	"Renaming $autocompletecachedir\$($Oldacc.name) to $($currentacc.name)"
	rename-item -path  "$autocompletecachedir\$($Oldacc.name)" -NewName "$($currentacc.name)"
}
Else{"No Autocomplete file found."}

}
else {
"No Autocomplete cache found. Aborting..."
}
"Done! Please check Outlook and confirm the results."
}

Hopefully this will be end of your google search for now!

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *