27 June 2014

Pinning Shortcuts to the Taskbar and Start Menu

There are already scripts out there that will do this, but I have taken it a little further. I have added checking to make sure the application is installed first so that the script does not error out. I have also added on-screen display to show if it was successful or not. I originally started off of the answer here and then expanded. One weird thing I encountered while writing this was that it treated excel 2010 differently than all other shortcuts. That is why you will see the extra three lines of code specifically for excel. You can download the script from here.

You can download the script from here.

There is a newer version located here.


 <#  
 .NAME  
   Mick Pletcher  
 .DATE  
   11 May 2014  
 .SYNOPSIS  
   Taskbar Shortcuts  
 .DESCRIPTION  
   Create taskbar shortcuts  
 .PARAMETER <paramName>  
   <Description of script parameter>  
 .EXAMPLE  
   <An example of using the script>  
 #>  
   
 #Declare Global Memory  
 Set-Variable -Name Architecture -Scope Global -Force  
 Set-Variable -Name RelativePath -Scope Global -Force  
 Set-Variable -Name Title -Value "Application Shortcuts" -Scope Global -Force  
   
 Function ConsoleTitle ($Title){  
      $host.ui.RawUI.WindowTitle = $Title  
 }  
   
 Function GetRelativePath {   
      $Global:RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"   
 }  
   
 Function GetArchitecture {  
      $Global:Architecture = Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture  
      $Global:Architecture = $Global:Architecture.OSArchitecture  
      #Returns 32-bit or 64-bit  
 }  
   
 Function PinToStartMenu ($AppName,$PinnedApp,$App) {  
      Write-Host "Pin"$AppName" on Start Menu....." -NoNewline  
      If ((Test-Path $App) -eq $true) {  
           If ((Test-Path $PinnedApp) -eq $false) {  
                $sa = new-object -c shell.application  
                $AppSplit = $App.split("\")  
                $AppSplitCount = $AppSplit.Count  
                $Filename = $AppSplit[$AppSplitCount-1]  
                For ($i=0; $i -lt $AppSplitCount-1) {  
                     $DirectoryPath = $DirectoryPath+$AppSplit[$i]  
                     If ($i -ne $AppSplitCount-2) {  
                          $DirectoryPath = $DirectoryPath+"\"  
                     }  
                     $i++  
                }  
                $pn = $sa.namespace($DirectoryPath).parsename($Filename)  
                $pn.invokeverb('startpin')  
                If ((Test-Path $PinnedApp) -eq $true) {  
                     Write-Host "Success" -ForegroundColor Yellow  
                } else {  
                     Write-Host "Failed " -ForegroundColor Red  
                }  
           } else {  
                Write-Host "Already Present" -ForegroundColor Yellow  
           }  
      } else {  
           Write-Host "Application not installed" -ForegroundColor Green  
      }  
 }  
   
 Function PinToTaskbar ($AppName,$PinnedApp,$App) {  
      Write-Host "Pin"$AppName" to Taskbar....." -NoNewline  
      If ((Test-Path $App) -eq $true) {  
           If ((Test-Path $PinnedApp) -eq $false) {  
                $sa = new-object -c shell.application  
                $AppSplit = $App.split("\")  
                $AppSplitCount = $AppSplit.Count  
                $Filename = $AppSplit[$AppSplitCount-1]  
                For ($i=0; $i -lt $AppSplitCount-1) {  
                     $DirectoryPath = $DirectoryPath+$AppSplit[$i]  
                     If ($i -ne $AppSplitCount-2) {  
                          $DirectoryPath = $DirectoryPath+"\"  
                     }  
                     $i++  
                }  
                $pn = $sa.namespace($DirectoryPath).parsename($Filename)  
                $pn.invokeverb('taskbarpin')  
                If ((Test-Path $PinnedApp) -eq $true) {  
                     Write-Host "Success" -ForegroundColor Yellow  
                } else {  
                     Write-Host "Failed " -ForegroundColor Red  
                }  
           } else {  
                Write-Host "Already Present" -ForegroundColor Yellow  
           }  
      } else {  
           Write-Host "Application not installed" -ForegroundColor Green  
      }  
 }  
   
 Function UnpinFromStartMenu ($AppName,$PinnedApp,$App) {  
      Write-Host "Unpin"$AppName" from Start Menu....." -NoNewline  
      If ((Test-Path $PinnedApp) -eq $true) {  
           $sa = new-object -c shell.application  
           $AppSplit = $App.split("\")  
           $AppSplitCount = $AppSplit.Count  
           $Filename = $AppSplit[$AppSplitCount-1]  
           For ($i=0; $i -lt $AppSplitCount-1) {  
                $DirectoryPath = $DirectoryPath+$AppSplit[$i]  
                If ($i -ne $AppSplitCount-2) {  
                     $DirectoryPath = $DirectoryPath+"\"  
                }  
                $i++  
           }  
           $pn = $sa.namespace($DirectoryPath).parsename($Filename)  
           $pn.invokeverb('startunpin')  
           If ((Test-Path $PinnedApp) -eq $false) {  
                Write-Host "Success" -ForegroundColor Yellow  
           } else {  
                Write-Host "Failed " -ForegroundColor Red  
           }  
      } else {  
           Write-Host "Already Removed" -ForegroundColor Yellow  
      }  
 }  
   
 Function UnpinFromTaskbar ($AppName,$PinnedApp,$App) {  
      Write-Host "Unpin"$AppName" from Taskbar....." -NoNewline  
      If ((Test-Path $PinnedApp) -eq $true) {  
           $AppSplit = $App.split("\")  
           $AppSplitCount = $AppSplit.Count  
           $Filename = $AppSplit[$AppSplitCount-1]  
           $DirectoryPath = $App.Trim($Filename)  
           $DirectoryPath = $DirectoryPath.Trim("\")  
           If ($Filename -eq "EXCEL.EXE") {  
                $DirectoryPath = "c"+$DirectoryPath  
           }  
           $sa = new-object -c shell.application  
           $pn = $sa.namespace($DirectoryPath).parsename($Filename)  
           $pn.invokeverb('taskbarunpin')  
           If ((Test-Path $PinnedApp) -eq $false) {  
                Write-Host "Success" -ForegroundColor Yellow  
           } else {  
                Write-Host "Failed " -ForegroundColor Red  
           }  
      } else {  
           Write-Host "Already Removed" -ForegroundColor Yellow  
      }  
 }  
   
 cls  
 GetRelativePath  
 ConsoleTitle $Global:Title  
 GetArchitecture  
 If ($Global:Architecture -eq "32-bit") {  
      UnpinFromStartMenu "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook.lnk" "C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"  
      UnpinFromStartMenu "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word.lnk" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"  
      UnpinFromStartMenu "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel.lnk" "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"  
      UnpinFromStartMenu "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft PowerPoint.lnk" "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE"  
      UnpinFromStartMenu "eDocs DM" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Open Text eDocs Email Marker.lnk" "C:\Program Files\Open Text\Email Filing\DMMarkEmail.exe"  
      PinToStartMenu "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook.lnk" "C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"  
      PinToStartMenu "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word.lnk" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"  
      PinToStartMenu "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel.lnk" "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"  
      PinToStartMenu "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft PowerPoint.lnk" "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE"  
      UnpinFromTaskbar "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Outlook 2010.lnk" "C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"  
      UnpinFromTaskbar "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Word 2010.lnk" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"  
      UnpinFromTaskbar "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Excel 2010.lnk" "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"  
      UnpinFromTaskbar "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft PowerPoint 2010.lnk" "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE"  
      PinToTaskbar "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Outlook 2010.lnk" "C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE"  
      PinToTaskbar "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Word 2010.lnk" "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE"  
      PinToTaskbar "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Excel 2010.lnk" "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"  
      PinToTaskbar "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft PowerPoint 2010.lnk" "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE"  
 } else {  
      UnpinFromStartMenu "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"  
      UnpinFromStartMenu "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE"  
      UnpinFromStartMenu "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"  
      UnpinFromStartMenu "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft PowerPoint.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE"  
      PinToStartMenu "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"  
      PinToStartMenu "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE"  
      PinToStartMenu "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"  
      PinToStartMenu "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft PowerPoint.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE"  
      UnpinFromTaskbar "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Outlook 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"  
      UnpinFromTaskbar "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Word 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE"  
      UnpinFromTaskbar "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Excel 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"  
      UnpinFromTaskbar "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft PowerPoint 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE"  
      PinToTaskbar "Outlook" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Outlook 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"  
      PinToTaskbar "Word" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Word 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE"  
      PinToTaskbar "Excel" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Excel 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"  
      PinToTaskbar "PowerPoint" $Env:APPDATA"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft PowerPoint 2010.lnk" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE"  
 }  
 

Related Posts:

  • MSI Analysis Reporting Tool Here is a tool I have written that generates a report on all of the variables used for each entry during an MSI installation. I wrote this script to make customizing the installation of MSI files much easier and quicker. Th… Read More
  • OS Detection Recently, we added the Windows 8.1 operating system to the company domain. I ran into the problem of deploying Adobe Flash Player to these systems because the ActiveX does not get installed. The issue came up in SCCM where … Read More
  • Cleaning up old systems in Active Directory, SCCM, and Antivirus Every place I have worked, there has been the issue of systems being in SCCM, AD, and antivirus that no longer existed. The is often caused by systems being overlooked when a user departs the company, a laptop that gets put… Read More
  • SCCM Client Installer This PowerShell script will uninstall previous versions of SCCM client, run the CCMClean to make sure all instances of the client are gone off of the machine, and finally install the SCCM client. The script will not complet… Read More
  • Application List This script will generate a list of installed applications minus those in the exclusion list text file. I created this script so the help desk could have a concise list of applications that need to be installed post-build. … Read More

2 comments:

  1. Split-Path : Cannot bind argument to parameter 'Path' because it is null.

    ReplyDelete
    Replies
    1. What OS are you using? It might not work on a different OS. I have it working on Windows 7 64-bit.

      Delete