Clearing AutoComplete and other Recipient Caches

Exchange 2010 Logo

Last version: 1.1, March 12th, 2016.

Anyone who has participated in migrations or transitions to Exchange has most likely encountered or has had to work around potential issues caused by the nickname cache. A “cache,” also known by its file extension, NK2 in older Outlook clients, is a convenience feature in Outlook and Outlook WebApp (OWA) which lets users pick recipients from a list of frequently-used recipients. This list is displayed when the end user types in the first few letters.

The potential issue revolves around end users using those lists to send messages, as the list contains cached recipient information. Because this information is static, it may become invalid at some point. Thus, when users pick recipients when sending messages, they may be sending messages to non-existent recipients or invalid e-mail addresses, which create issues like non-delivery of e-mail.

Read the full article over on ENow Solutions Engine blog.

Clean-AutoComplete

Using the script mentioned in the article, which can be used to clear cached recipient information, is straightforward. It requires Exchange 2010 or later and Exchange Web Services Managed API 1.2 (or later) which you can download here. Alternatively, you can copy the Microsoft.Exchange.WebServices.DLL with the script as it will also look for it in the current folder.

The script Clean-AutoComplete.ps1 has the following syntax:

Clear-AutoComplete.ps1 [-Mailbox] <String> [-Server <String>] [-Impersonation] [-Credentials <PSCredential>] [-Type <Array>]

Where:

  • Mailbox is the name or e-mail address of the mailbox.
  • Server is the name of the Client Access Server to access for Exchange Web Services. When omitted, the script will use AutoDiscover.
  • Switch Impersonation specifies if impersonation will be used for mailbox access, otherwise the current user context will be used.
  • Credentials specifies the user credentials to use.
  • Type specifies what cached recipient information to clear. Options are Outlook  (Outlook AutoComplete stream), OWA (OWA Autocomplete stream), SuggestedContacts, RecipientCache or All. Default is Outlook,OWA.

So for example, suppose you want to clear the Autocomplete stream used by Outlook on a mailbox, you can use:

Clear-AutoComplete.ps1 -Mailbox Olrik -Type Outlook -Verbose

ScreenCapTo remove the Autocomplete stream used by OWA on your Office 365 account, you can use:

Clear-AutoComplete.ps1 -Mailbox olrik@office365tenant.com –Credentials (Get-Credential) –Type OWA

Be advised that clearing the Outlook AutoComplete stream will only have effect for Outlook running in Online mode. Outlook caches this information as well in the OST file, leaving the options of running Outlook with the /CleanAutocompleteCache switch, or remove and let Outlook recreate the OST file. The temporary Stream_AutoComplete files*.dat files created under %USERPROFILE%\AppData\Local\Microsoft\Outlook\RoamCache are used by Outlook to speed things up.

Disabling Auto-Complete and Suggested Contacts
Alternatively, you can disable Auto-Complete, the equivalent of unchecking the Outlook option ‘Use Auto-Complete List to suggest names when typing in the To, Cc and Bcc line‘, by setting the following registry key:

Note: In the examples below, you need to modify the version number in the examples corresponding to the Outlook version you wish to apply these settings against. Use 16.0 as indicated for Outlook 2016, but change it to 15.0 for Outlook 2013, or 14.0 for Outlook 2010.

HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Preferences\
ShowAutoSug=0 (REG_DWORD)

To configure this setting using a Group Policy, use the following registry setting:

HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\Outlook\Preferences\ShowAutoSug=0 (REG_DWORD)

You can also disable Suggested Contacts folder, the equivalent of unchecking the Outlook option ‘Automatically create Outlook contacts for recipients that do not belong to an Outlook Address Book’, with the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\office\16.0\Outlook\Contact\CreateContactsForOneOffs= 0 (REG_DWORD)

The related Group Policy setting is:

HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\Outlook\Contact\CreateContactsForOneOffs= 0 (REG_DWORD)

Feedback
Feedback is welcomed through the comments. If you got scripting suggestions or questions, do not hesitate using the contact form.

Download
You can download the script from my Technet Gallery here.

Revision History
See Technet Gallery page.

 

 

27 thoughts on “Clearing AutoComplete and other Recipient Caches

  1. Pingback: Weekly IT Newsletter – July 14-18, 2014 | Just a Lync Guy

  2. Pingback: NeWay Technologies – Weekly Newsletter #104 – July 17, 2014 | NeWay

  3. Pingback: NeWay Technologies – Weekly Newsletter #104 – July 18, 2014 | NeWay

  4. I’m receiving the following error message. Any suggestions?

    PS C:\Office365\PowerShell> .\Clear-AutoComplete.ps1 -mailbox xxx@domain -Server outlook.office365.com -type All -Verbose
    VERBOSE: Loading C:\Program Files\Microsoft\Exchange\Web Services\2.0\\Microsoft.Exchange.WebServices.dll
    VERBOSE: Loaded Microsoft.Exchange.WebServices v15.0.0.0
    Processing mailbox xxx@domain
    VERBOSE: Set to trust all certificates
    VERBOSE: Using Exchange Web Services URL https://outlook.office365.com/EWS/Exchange.asmx
    C:\Office365\PowerShell\Clear-AutoComplete.ps1 : Can’t access mailbox information store
    At line:1 char:1
    + .\Clear-AutoComplete.ps1 -mailbox xxx@domain -Server outlook.office3 …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Clear-AutoComplete.ps1

    Also tried the following:

    PS C:\Office365\PowerShell> .\Clear-AutoComplete.ps1 -mailbox xxx@domain -type All -Verbose
    VERBOSE: Loading C:\Program Files\Microsoft\Exchange\Web Services\2.0\\Microsoft.Exchange.WebServices.dll
    VERBOSE: Loaded Microsoft.Exchange.WebServices v15.0.0.0
    Processing mailbox xxx@domain
    VERBOSE: Set to trust all certificates
    VERBOSE: Looking up EWS URL using Autodiscover for xxx@domain
    C:\Office365\PowerShell\Clear-AutoComplete.ps1 : A positional parameter cannot be found that accepts argument ‘Exception calling “AutodiscoverUrl” with “2” argument(s): “The Autodiscover service couldn’t be located.”‘.
    At line:1 char:1
    + .\Clear-AutoComplete.ps1 -mailbox xxx@domain -type All -Verbose
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Clear-AutoComplete.ps1], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Clear-AutoComplete.ps1

    • 1) “Can’t access mailbox information store”.
      Seems like permission issue, see https://eightwone.com/2014/08/13/application-impersonation-to-be-or-pretend-to-be/

      2) “The Autodiscover service couldn’t be located”
      The Autodiscover service is not configured for @domain or there is a problem accessing it or a problem with Autodiscover.

      Are you running this for an Office 365 mailbox? Are you running this for on-prem for an on-prem mailbox?

      • I get a similar “AutodiscoverUrl” error.

        VERBOSE: Loading C:\Program Files\Microsoft\Exchange\Web Services\2.2\\Microsoft.Exchange.WebServices.dll
        VERBOSE: Loaded Microsoft.Exchange.WebServices v15.0.0.0
        Processing mailbox user123@xyz.onmicrosoft.com (user123@xyz.onmicrosoft.com)
        VERBOSE: Set to trust all certificates
        VERBOSE: Using credentials user123
        VERBOSE: Looking up EWS URL using Autodiscover for user123@xyz.onmicrosoft.com
        C:\Users\user123\Clear-AutoComplete.ps1 : A positional parameter cannot be found that accepts argument ‘Exception
        calling “AutodiscoverUrl” with “2” argument(s): “The Autodiscover service couldn’t be located.”‘.
        At line:1 char:1
        + .\clear-autocomplete.ps1 -Mailbox user123@xyz.onmicrosoft.com
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidArgument: (:) [Clear-AutoComplete.ps1], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Clear-AutoComplete.ps1

        What is the Autodiscover service, and do I “need” it for this script/process to run/work?

        Thanks,
        Dave

    • You must close Outlook to close the cache.
      Outlook just write the cleared cache when you exit Outlook

  5. Hi Michel,

    I’m working on a Exchange2013 On-Premise installation and got your script run with a few changes:

    – line 240: $Folder.Empty() needs two parameters. Second one could be $true/$false for the recursive folder deletion. It’s mandatory

    – line 260: $RecipientCacheFolder.Empty() needs two parameters. Second one could be $true/$false for the recursive folder deletion. It’s mandatory

    – line 287: [Microsoft.Exchange.WebServices.Data.ExchangeVersion] changed from “Exchange2010_SP1” to “Exchange2013”

    I also had to run the following cmdlet to let the impersonation work as expected:

    New-ManagementRoleAssignment –Name:impersonationAssignmentName Role:ApplicationImpersonation –User:()

    Regards,

    Simone

    • Thanks for the feedback. Note that you can use Exchange2010 ‘mode’ to communicate against Exchange 2013+, it’s only to unlock Exchange2013+ specific operations (and syntax as you found out 🙂 ).

  6. Pingback: Something More about Autocomplete | nehrunotes

  7. Hi, I get the following error:

    C:\Scripts\Migration\LMH\Clear-AutoComplete.ps1 : Can’t access mailbox information store
    At line:1 char:25
    + .\Clear-AutoComplete.ps1 <<<< -Mailbox tabcd -Credentials $cred -Type All -Verbose -Server owa.ynhh.org
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Clear-AutoComplete.ps1

    I'm using an account that has full access to all mailboxes. Should I use the Impersonation option instead?

    • Here is the verbose information:

      [PS] C:\Scripts\Migration\LMH>.\Clear-AutoComplete.ps1 -Mailbox tabcd -Credentials $cred -Type All -Verbose -Server NLBNAME
      VERBOSE: Loading C:\Scripts\Migration\LMH\Microsoft.Exchange.WebServices.dll
      VERBOSE: Loaded Microsoft.Exchange.WebServices v14.0.0.0
      Processing mailbox tabcd (Test.ABCD@domain.com)
      VERBOSE: Set to trust all certificates
      VERBOSE: Using credentials account info
      VERBOSE: Using Exchange Web Services URL https://NLBNAME/EWS/Exchange.asmx
      C:\Scripts\Migration\LMH\Clear-AutoComplete.ps1 : Can’t access mailbox information store
      At line:1 char:25
      + .\Clear-AutoComplete.ps1 <<<< -Mailbox tabcd -Credentials $cred -Type All -Verbose -Server owa.ynhh.org
      + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Clear-AutoComplete.ps1

    • Does the account have proper full permissions configured, and you took into account a period to wait for FMA to become effective?
      Configure impersonation and try that route; if that works, there was perhaps something wrong with (in-mailbox) permissions.
      If it doesn’t, is there perhaps a firewall blocking port 443 traffic on that port?

      • Hi Michael, Thanks for the quick response. This is on-prem, so the firewall blocking should not come into play, correct?

        I just tired again and if failed again.

        My account does have impersonation rights:
        MAImpersonationAssignmentNa… ApplicationImpersonation Boluk, Sahin User Direct Boluk, Sahin

              • Hi Michael,
                I figured out how to run the script. I was using domain\ID, and I tried UserID@domain and that works now.

                Only thing is, it runs but doesn’t clear the cache. I tested with a test account, and below is the output, says no item found, but there is on the mailbox, any thoughts?

                VERBOSE: Loading C:\Scripts\Migration\LMH\Microsoft.Exchange.WebServices.dll
                VERBOSE: Loading module from path ‘C:\Scripts\Migration\LMH\Microsoft.Exchange.WebServices.dll’.
                VERBOSE: Loaded Microsoft.Exchange.WebServices v14.0.0.0
                Processing mailbox xxxxxx
                VERBOSE: Set to trust all certificates
                VERBOSE: Using credentials xxxxxx
                VERBOSE: Using Exchange Web Services URL https://xxxxxx/EWS/Exchange.asmx
                VERBOSE: No AutoComplete Stream item found.
                VERBOSE: No OWA AutoComplete item found.
                VERBOSE: No ‘Suggested Contacts’ folder found.
                VERBOSE: No RecipientCache folder found.

  8. Hello Michel! Thank you for the article and the script, greatly appreciate it. Recently we had someone setup a user incorrectly, which we then had to re-create with the proper name. After which, some of our users can email correctly, but others cannot email. We seem to get a NDR, mainly when using the Auto-Complete. I stumbled across your article and figured I’d give it a try but when running I am seeing the following:

    New-Object : Multiple ambiguous overloads found for “ExchangeService” and the argument count: “1”.
    At C:\temp\Clear-AutoComplete.ps1:291 char:22
    + $EwsService= New-Object Microsoft.Exchange.WebServices.Data.ExchangeServ …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

    The property ‘UseDefaultCredentials’ cannot be found on this object. Verify that the property exists and can be set.
    At C:\temp\Clear-AutoComplete.ps1:292 char:9
    + $EwsService.UseDefaultCredentials= $true
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

    The property ‘UseDefaultCredentials’ cannot be found on this object. Verify that the property exists and can be set.
    At C:\temp\Clear-AutoComplete.ps1:305 char:13
    + $EwsService.UseDefaultCredentials= $true
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

    VERBOSE: Looking up EWS URL using Autodiscover for {MAILBOX NAME}
    C:\temp\Clear-AutoComplete.ps1 : Autodiscover failed: You cannot call a method on a null-valued expression.
    At line:1 char:1
    + .\Clear-AutoComplete.ps1 -Mailbox {MAILBOX NAME} -Type Outlook -Verbose
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Clear-AutoComplete.ps1

    Any thoughts as to what would be causing this? I am running the Exchange Management PS as a domain admin account, on the Exchange server and have ensured the API is installed as well.

    Thanks in advance,
    Kyle

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s