Citrix XenApp & Office 2016 – AutoCorrect Entries Disappearing


I recently came across an issue with Office 2016 and Citrix XenApp where by a user’s Word autocorrect entries would be wiped intermittently during a live session. After a quick search I found that Microsoft’s product support have identified this as a known issue and have provided a work around ; http://answers.microsoft.com/en-us/office/forum/office_2016-word/normal-template-wiped-again/a96dba06-68f7-40e8-a1a2-55ddef1bcca7?auth=1.

The issue here is that the work around requires users to access their AppData folder and modify files based on date, not something you would want Citrix user sessions to have to do.

So I came up with a work around for my environment using PowerShell.

Step1. Backup AutoCorrect Entries
For this process I use the following PS script running as part of a log off script process in a GPO. The backup process will only replace previous backups whereby the file size exceeds that of the previous backup (as users tend to keep adding autocorrect entries and thus the file size increases);


<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.99
Created on: 01/03/2016 12:32
Created by: Maurice.Daly
Organization:
Filename:
===========================================================================
.DESCRIPTION
Word Autotext Backup Script
#>

$AutoTextLocation = $env:APPDATA + "\Microsoft\Templates"
$BackupLocation = [environment]::GetFolderPath("MyDocuments") + "\AutoTextBackup"

If ((Test-Path -Path $BackupLocation) -eq $false)
{
$AutoCorrectFiles = Get-ChildItem -Path $AutoTextLocation | Where-Object { $_.Name -like "Normal*.*" }
New-Item $BackupLocation -Type dir
Copy-Item -Path $AutoCorrectFiles.FullName -Destination $BackupLocation
}else{
$AutoCorrectFiles = Get-ChildItem -Path $AutoTextLocation | Where-Object { $_.Name -like "Normal*.*" }
foreach ($File in $AutoCorrectFiles)
{
if ((Get-Item -Path $File.FullName).Length -gt (Get-ChildItem -Path ($BackupLocation + "\" + $File.Name)).Length)
{
Copy-Item -Path $File.FullName -Destination $BackupLocation -Verbose
}
}
}

Step 2. Restoring AutoCorrect Entries
The following PowerShell script can be run automatically via a log on PS script in a GPO or in my instance I opted to publish the script via XenApp so that users can restore data when an issue arises;


<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.99
Created on: 01/03/2016 12:32
Created by: Maurice.Daly
Organization:
Filename:
===========================================================================
.DESCRIPTION
Word Autotext Restore Script
#>

$AutoTextLocation = $env:APPDATA + "\Microsoft\Templates"
$BackupLocation = [environment]::GetFolderPath("MyDocuments") + "\AutoTextBackup"
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$ConfirmRestore = [System.Windows.Forms.MessageBox]::Show("Citrix instances Word and Outlook will now close to restore your AutoCorrect files.", "Restore Office AutoCorrect", 4)
if ($ConfirmRestore -eq "YES"){
$OfficeApps = "Winword.exe", "Outlook.exe"
foreach ($App in $OfficeApps)
{
Taskkill.exe /FI "Username eq $env:Username" /IM $App
}
Sleep -Seconds 5
Write-Host -ForegroundColor Green "Removing current autocorrect template files"
Get-ChildItem -Path $AutoTextLocation | Where-Object { $_.Name -like "normal*.*" } | Remove-Item -Force -ErrorAction Continue
Write-Host -ForegroundColor Green "Restoring autocorrect templates from backup location"
Get-ChildItem -Path $BackupLocation | Copy-Item -Destination $AutoTextLocation -Force
if ((Get-ChildItem -Path $BackupLocation).Count -eq (Get-ChildItem -Path $AutoTextLocation | Where-Object { $_.Name -like "normal*.*" }).Count)
{
[System.Windows.Forms.MessageBox]::Show("AutoCorrect files succesfully restored.", "Restore Office AutoCorrect")}else{ [System.Windows.Forms.MessageBox]::Show("AutoCorrect files restore unsuccessful. Please contact IT.", "Restore Office AutoCorrect")}
}
else { Exit }

The PowerShell scripts assume that you using re-mapped My Documents as a backup location and that you want some form of interactivity during the restore process, i.e to advise them that Word and Outlook will be terminated and whether or not the restore process was successful. Obviously you can chop/change this as required but it does the trick.

Hopefully this helps some of you with this issue.

 

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