Skip to main content

Powershell Script to install MS Office Templates

To deploy custom Office templates for users first create the templates , preview image files and thumbnail image files per the MS article: https://technet.microsoft.com/en-us/library/cc178976%28v=office.14%29.aspx#section4 and create a .reg file to set the provider keys to point to the XML, create different reg files for office 2010 and 2013, change the service URL to whatever location the XML is located at :


Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common\Spotlight\Providers\Workaround]
"ServiceURL"="C:\\Program Files (x86)\\Microsoft Office\\Templates\\Workaround\\Workaround_Templates.xml"

Place templates, images and the XML into a folder within the script and adjust the variables in the script accordingly:

#############Install FICO templates####################
#Author: tausif
#Company: FICO
#Date: 13/02/2016

#---------------------------------------------------------[Initialisations]--------------------------------------------------------

#Set Error Action to Silently Continue
#$ErrorActionPreference = "SilentlyContinue"

#----------------------------------------------------------[Declarations]----------------------------------------------------------

#Script Version
$sScriptVersion = "1.0"
#script root

$PSScriptRoot = ($MyInvocation.MyCommand.Path | Split-Path | Resolve-Path).ProviderPath

#logging variables.
$logdir = "$($env:ALLUSERSPROFILE)\InstallLogs"
$Logfile = "$($logdir)\FICO_2016_Templates_$(get-date -format `"yyyyMMdd_hhmmsstt`").log"

$FICOTEMPLATESDIR = "$($env:ALLUSERSPROFILE)\FICO Templates"
$PROGRAMDATA = $env:ALLUSERSPROFILE

Function LogWrite($string, $color)
{
   if ($Color -eq $null) {$color = "white"}
   write-host $string -foregroundcolor $color
   $string | out-file -Filepath $logfile -append
}

if(!(Test-Path -Path $logdir )){
    New-Item -ItemType directory -Path $logdir
}


########################################

$CP_USER_NAME = (Get-WmiObject Win32_ComputerSystem | Select-Object -ExpandProperty UserName).Split('\')[1]
$user = New-Object System.Security.Principal.NTAccount("corp", "$CP_USER_NAME") 
$sid = $user.Translate([System.Security.Principal.SecurityIdentifier]) 
$userprofile = Get-WmiObject -Namespace root/cimv2 -Class win32_userprofile -Filter "SID='$($sid.value)'"
$CP_USER_HOME = $userprofile.localpath
$CP_USER_TEMPLATESDIR = "$CP_USER_HOME" + "\" + "AppData\Roaming\Microsoft\Templates"
$FICO_USER_TEMPLATESDIR = "$CP_USER_HOME" + "\" + "AppData\Roaming\Microsoft\Templates\FICO Templates"

if(Test-Path -Path $FICOTEMPLATESDIR){
    Remove-Item -Path $FICOTEMPLATESDIR -Force -Recurse
    LogWrite "Removed existing older Template provider keys"
}

Copy-Item "$PSScriptRoot\FICO Templates" -Destination $PROGRAMDATA -Force -Recurse
LogWrite "Copied Office templates to destination"

# Set PowerPoint exe locations
$x86_PP_2013 = "${env:PROGRAMFILES(X86)}\Microsoft Office\Office15\POWERPNT.EXE"
$x64_PP_2013 = "${env:COMMONPROGRAMFILES}\Microsoft Office\Office15\POWERPNT.EXE"
$x86_PP_2010 = "${env:PROGRAMFILES(X86)}\Microsoft Office\Office14\POWERPNT.EXE"
$x64_PP_2010 = "${env:COMMONPROGRAMFILES}\Microsoft Office\Office14\POWERPNT.EXE"

#Set providers using reg files
$2010 = "$PSScriptRoot\2010.reg"
$2013 = "$PSScriptRoot\2013.reg"

# X64 OS and Office 2013
if (test-path $x64_PP_2013)
    { 
        LogWrite "64 bit office present"
        Remove-Item -Path HKCU:\Software\Microsoft\Office\15.0\Common\Spotlight\Providers\* -Recurse
        Remove-Item -Path HKCU:\Software\Microsoft\Office\15.0\Common\Spotlight\Content\* -Recurse
        $import = $(Start-Process "regedit.exe" -argumentlist ("/s", "$2013") -Wait -PassThru)
        if ($import.ExitCode -eq 0){
            LogWrite "Templates for Office 2013 have been successfully installed" -color yellow
        }
            else {
            LogWrite "installer exit code  $($import.ExitCode) for file  $($msifile)" -color red
        }
    }
 
# X64 OS and Office 2010
if (test-path $x64_PP_2010)
    { 
        LogWrite "64 bit office 2010 present"
        Remove-Item -Path HKCU:\Software\Microsoft\Office\14.0\Common\Spotlight\Providers\* -Recurse
        Remove-Item -Path HKCU:\Software\Microsoft\Office\15.0\Common\Spotlight\Content\* -Recurse
        $import = $(Start-Process "regedit.exe" -argumentlist ("/s", "$2010") -Wait -PassThru)
        if ($import.ExitCode -eq 0){
            LogWrite "Templates for Office 2010 have been successfully installed" -color yellow
        }
            else {
            LogWrite "installer exit code $($import.ExitCode)" -color red
        }
    }
# X86 OS and Office 2013
if (test-path $x86_PP_2013)
    { 
        LogWrite "32 bit office 2013 present"
        Remove-Item -Path HKCU:\Software\Microsoft\Office\14.0\Common\Spotlight\Providers\* -Recurse
        Remove-Item -Path HKCU:\Software\Microsoft\Office\15.0\Common\Spotlight\Content\* -Recurse
        $import = $(Start-Process "regedit.exe" -argumentlist ("/s", "$2013") -Wait -PassThru)
        if ($import.ExitCode -eq 0){
            LogWrite "Templates for Office 2013 have been successfully installed" -color yellow
        }
            else {
            LogWrite "installer exit code $($import.ExitCode)" -color red
        }
    }
# X86 OS and Office 2010
if (test-path $x86_PP_2010)
    { 
        LogWrite "32 bit office 2010 present"
        Remove-Item -Path HKCU:\Software\Microsoft\Office\14.0\Common\Spotlight\Providers\* -Recurse
        Remove-Item -Path HKCU:\Software\Microsoft\Office\15.0\Common\Spotlight\Content\* -Recurse
        $import = $(Start-Process "regedit.exe" -argumentlist ("/s", "$2010") -Wait -PassThru)
        if ($import.ExitCode -eq 0){
            LogWrite "Templates for Office 2010 have been successfully installed" -color yellow
        }
            else {
            LogWrite "installer exit code $($import.ExitCode)" -color red
        }
    } 

This script creates logs in C:\ProgramData\InstallLogs
and copies templates, images and XML to C:\ProgramData\FICO Templates


Comments

  1. Very nice script, do you by chance have an updated one that works for 2016? Seems the Spotlight diretory has been removed and some searching notes to use use the Common / General directory for the ServiceURL

    ReplyDelete

Post a Comment

Popular posts from this blog

Removing corporate wireless restrictions completely : "The policies of your network prevent the creation of ad hoc (computer-to-computer) networks. For more information, contact your system administrator."

So i was recently tasked with removing wireless restrictions from a VP's windows 7 laptop that some infrastructure company had placed while contracted with our network, since he needed to enable setting up of adhoc connections on his laptop and he always got

"The policies of your network prevent the creation of ad hoc (computer-to-computer) networks. For more information, contact your system administrator."


A little bit of probing revealed that adhoc and peer to peer connections were blocked as evidenced by the the command 

netsh wlan show filter on an  elevated command prompt revealed that adhoc network type was blocked by group policy:

I removed the restrictions by:

1: open services.msc as administrator, scroll down to WLAN AutoConfig:

To Unlock Windows Update locked due to group policy.

To Unlock Windows Update locked due to group policy.




Open gpedit.msc and browse to the location /Computer Configuration/Administrative Templates/System/Internet Communication Management/Internet Communication Settings and double click "turn off access to all windows update features" and set it to disabled.

Migrating Outlook Profile to Office 365

We had a migration from Hosted Exchange to Office 365 and i was tasked with automating the local Outloook profile migration for Users:

I Created a GUI utility using powershell which would allow users to create an Office365 Profile and set it as default, I prepared PRF files for each version of office and an autodiscover.xml to be used for local autodiscover and uploaded them to a hosted site:

The PRF file to set settings for Office 365 are hard to find: i used the below entries:


;AutomaticallygeneratedPRFfilefromtheMicrosoftOfficeCustomizationandInstallationWizard;**************************************************************;Section1-ProfileDefaults;**************************************************************[General]Custom=1ProfileName=%UserName%-O365DefaultProfile=YesOverwriteProfile=YesModifyDefaultProfileIfPresent=false;**************************************************************;Section2-ServicesinProfile;**************************************************************[Service…