Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Global variable with the "All Users" Start Menu Path
  2. # Note this option is only available woth .NET Framework 4 or later
  3. if($PSVersionTable.CLRVersion.Major -ge 4) {
  4.     $global:CommonStartMenuDir = [environment]::getfolderpath("CommonStartMenu")
  5.     $global:CommonStartMenuProgramsDir = [environment]::getfolderpath("CommonPrograms")
  6. } elseif($VistaOrLater) {
  7.     $global:CommonStartMenuDir = "$env:ALLUSERSPROFILE\Microsoft\Windows\Start Menu"
  8.     $global:CommonStartMenuProgramsDir = "$CommonStartMenuDir\Programs"
  9. } else {
  10.     $global:CommonStartMenuDir = "$env:ALLUSERSPROFILE\Start Menu"
  11.     $global:CommonStartMenuProgramsDir = "$CommonStartMenuDir\Programs"
  12. }
  13.  
  14. # Global variable with the path to user Desktop
  15. $global:UserDesktopDir = [environment]::getfolderpath("Desktop")
  16.  
  17. function Repair-OfficeShortcuts
  18. {
  19.     <#
  20.      .Synopsis
  21.      Users often put shortcuts to Office applications on their desktop and taskbar.
  22.      After upgrading from Office 2013 to 2016, these shortcuts point to the old version will be broken.
  23.      This will catch old 2013 shortucts and fix them up to use the 2016 ones.
  24.     #>
  25.  
  26.     Write-Output "-- ENTERING FUNCTION $($MyInvocation.MyCommand) $($(Get-Date))..."
  27.  
  28.     Write-Output "-- Replacing Outlook 2013 shortcuts with 2016 (if needed)..."
  29.     if((Test-Path "$CommonStartMenuProgramsDir\Outlook 2016.lnk") -and (Test-Path "$UserDesktopDir\Outlook 2013.lnk"))
  30.     {
  31.         # Unpin the old shortcut from the Taskbar.
  32.         Write-Output "-- Unpinning old shortcut from taskbar..."
  33.         $shell = new-object -com "Shell.Application"  
  34.         $folder = $shell.Namespace("$UserDesktopDir")    
  35.         $item = $folder.Parsename('Outlook 2013.lnk')
  36.         $verb = $item.Verbs() | ? {$_.Name -eq 'Unpin from tas&kbar'}
  37.         if ($verb) {$verb.DoIt()}
  38.  
  39.         # Remove the old shortcut
  40.         Write-Output "-- Deleting old shortcut from desktop..."
  41.         Remove-File "$UserDesktopDir\Outlook 2013.lnk"
  42.  
  43.         # Copy the new shortcut to the desktop
  44.         Write-Output "-- Copying new shortcut to desktop..."
  45.         Copy-Item -Path "$CommonStartMenuProgramsDir\Outlook 2016.lnk" -Destination $UserDesktopDir -Force
  46.  
  47.         # Pin the new shortcut to the taskbar
  48.         # This does not work in Windows 10 for reasons unknown.
  49.         Write-Output "-- Pinning new shortcut to taskbar..."
  50.         $shell = new-object -com "Shell.Application"  
  51.         $folder = $shell.Namespace("$UserDesktopDir")    
  52.         $item = $folder.Parsename('Outlook 2016.lnk')
  53.         $verb = $item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar'}
  54.         if ($verb) {$verb.DoIt()}
  55.     }
  56.  
  57.     Write-Output "-- Replacing Word 2013 shortcuts with 2016 (if needed)..."
  58.     if((Test-Path "$CommonStartMenuProgramsDir\Word 2016.lnk") -and (Test-Path "$UserDesktopDir\Word 2013.lnk"))
  59.     {
  60.         # Unpin the old shortcut from the Taskbar.
  61.         Write-Output "-- Unpinning old shortcut from taskbar..."
  62.         $shell = new-object -com "Shell.Application"  
  63.         $folder = $shell.Namespace("$UserDesktopDir")    
  64.         $item = $folder.Parsename('Word 2013.lnk')
  65.         $verb = $item.Verbs() | ? {$_.Name -eq 'Unpin from tas&kbar'}
  66.         if ($verb) {$verb.DoIt()}
  67.  
  68.         # Remove the old shortcut
  69.         Write-Output "-- Deleting old shortcut from desktop..."
  70.         Remove-File "$UserDesktopDir\Word 2013.lnk"
  71.  
  72.         # Copy the new shortcut to the desktop
  73.         Write-Output "-- Copying new shortcut to desktop..."
  74.         Copy-Item -Path "$CommonStartMenuProgramsDir\Word 2016.lnk" -Destination $UserDesktopDir -Force
  75.  
  76.         # Dont bother pinning, most people don't have it pinned to their taskbar.
  77.     }
  78.  
  79.     Write-Output "-- Replacing Excel 2013 shortcuts with 2016 (if needed)..."
  80.     if((Test-Path "$CommonStartMenuProgramsDir\Excel 2016.lnk") -and (Test-Path "$UserDesktopDir\Excel 2013.lnk"))
  81.     {
  82.         # Unpin the old shortcut from the Taskbar.
  83.         Write-Output "-- Unpinning old shortcut from taskbar..."
  84.         $shell = new-object -com "Shell.Application"  
  85.         $folder = $shell.Namespace("$UserDesktopDir")    
  86.         $item = $folder.Parsename('Excel 2013.lnk')
  87.         $verb = $item.Verbs() | ? {$_.Name -eq 'Unpin from tas&kbar'}
  88.         if ($verb) {$verb.DoIt()}
  89.  
  90.         # Remove the old shortcut
  91.         Write-Output "-- Deleting old shortcut from desktop..."
  92.         Remove-File "$UserDesktopDir\Excel 2013.lnk"
  93.  
  94.         # Copy the new shortcut to the desktop
  95.         Write-Output "-- Copying new shortcut to desktop..."
  96.         Copy-Item -Path "$CommonStartMenuProgramsDir\Excel 2016.lnk" -Destination $UserDesktopDir -Force
  97.  
  98.         # Dont bother pinning, most people don't have it pinned to their taskbar.
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement