Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Global variable with the "All Users" Start Menu Path
- # Note this option is only available woth .NET Framework 4 or later
- if($PSVersionTable.CLRVersion.Major -ge 4) {
- $global:CommonStartMenuDir = [environment]::getfolderpath("CommonStartMenu")
- $global:CommonStartMenuProgramsDir = [environment]::getfolderpath("CommonPrograms")
- } elseif($VistaOrLater) {
- $global:CommonStartMenuDir = "$env:ALLUSERSPROFILE\Microsoft\Windows\Start Menu"
- $global:CommonStartMenuProgramsDir = "$CommonStartMenuDir\Programs"
- } else {
- $global:CommonStartMenuDir = "$env:ALLUSERSPROFILE\Start Menu"
- $global:CommonStartMenuProgramsDir = "$CommonStartMenuDir\Programs"
- }
- # Global variable with the path to user Desktop
- $global:UserDesktopDir = [environment]::getfolderpath("Desktop")
- function Repair-OfficeShortcuts
- {
- <#
- .Synopsis
- Users often put shortcuts to Office applications on their desktop and taskbar.
- After upgrading from Office 2013 to 2016, these shortcuts point to the old version will be broken.
- This will catch old 2013 shortucts and fix them up to use the 2016 ones.
- #>
- Write-Output "-- ENTERING FUNCTION $($MyInvocation.MyCommand) $($(Get-Date))..."
- Write-Output "-- Replacing Outlook 2013 shortcuts with 2016 (if needed)..."
- if((Test-Path "$CommonStartMenuProgramsDir\Outlook 2016.lnk") -and (Test-Path "$UserDesktopDir\Outlook 2013.lnk"))
- {
- # Unpin the old shortcut from the Taskbar.
- Write-Output "-- Unpinning old shortcut from taskbar..."
- $shell = new-object -com "Shell.Application"
- $folder = $shell.Namespace("$UserDesktopDir")
- $item = $folder.Parsename('Outlook 2013.lnk')
- $verb = $item.Verbs() | ? {$_.Name -eq 'Unpin from tas&kbar'}
- if ($verb) {$verb.DoIt()}
- # Remove the old shortcut
- Write-Output "-- Deleting old shortcut from desktop..."
- Remove-File "$UserDesktopDir\Outlook 2013.lnk"
- # Copy the new shortcut to the desktop
- Write-Output "-- Copying new shortcut to desktop..."
- Copy-Item -Path "$CommonStartMenuProgramsDir\Outlook 2016.lnk" -Destination $UserDesktopDir -Force
- # Pin the new shortcut to the taskbar
- # This does not work in Windows 10 for reasons unknown.
- Write-Output "-- Pinning new shortcut to taskbar..."
- $shell = new-object -com "Shell.Application"
- $folder = $shell.Namespace("$UserDesktopDir")
- $item = $folder.Parsename('Outlook 2016.lnk')
- $verb = $item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar'}
- if ($verb) {$verb.DoIt()}
- }
- Write-Output "-- Replacing Word 2013 shortcuts with 2016 (if needed)..."
- if((Test-Path "$CommonStartMenuProgramsDir\Word 2016.lnk") -and (Test-Path "$UserDesktopDir\Word 2013.lnk"))
- {
- # Unpin the old shortcut from the Taskbar.
- Write-Output "-- Unpinning old shortcut from taskbar..."
- $shell = new-object -com "Shell.Application"
- $folder = $shell.Namespace("$UserDesktopDir")
- $item = $folder.Parsename('Word 2013.lnk')
- $verb = $item.Verbs() | ? {$_.Name -eq 'Unpin from tas&kbar'}
- if ($verb) {$verb.DoIt()}
- # Remove the old shortcut
- Write-Output "-- Deleting old shortcut from desktop..."
- Remove-File "$UserDesktopDir\Word 2013.lnk"
- # Copy the new shortcut to the desktop
- Write-Output "-- Copying new shortcut to desktop..."
- Copy-Item -Path "$CommonStartMenuProgramsDir\Word 2016.lnk" -Destination $UserDesktopDir -Force
- # Dont bother pinning, most people don't have it pinned to their taskbar.
- }
- Write-Output "-- Replacing Excel 2013 shortcuts with 2016 (if needed)..."
- if((Test-Path "$CommonStartMenuProgramsDir\Excel 2016.lnk") -and (Test-Path "$UserDesktopDir\Excel 2013.lnk"))
- {
- # Unpin the old shortcut from the Taskbar.
- Write-Output "-- Unpinning old shortcut from taskbar..."
- $shell = new-object -com "Shell.Application"
- $folder = $shell.Namespace("$UserDesktopDir")
- $item = $folder.Parsename('Excel 2013.lnk')
- $verb = $item.Verbs() | ? {$_.Name -eq 'Unpin from tas&kbar'}
- if ($verb) {$verb.DoIt()}
- # Remove the old shortcut
- Write-Output "-- Deleting old shortcut from desktop..."
- Remove-File "$UserDesktopDir\Excel 2013.lnk"
- # Copy the new shortcut to the desktop
- Write-Output "-- Copying new shortcut to desktop..."
- Copy-Item -Path "$CommonStartMenuProgramsDir\Excel 2016.lnk" -Destination $UserDesktopDir -Force
- # Dont bother pinning, most people don't have it pinned to their taskbar.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement