0 Replies Latest reply on Oct 6, 2014 6:11 PM by gregf

    Pinning and unpinning items

    gregf SupportEmployee
      Here's some PowerShell code to pin items - without having to manage a module file

      To add more items to pin - just add to the {folder -> (target1, target2)} hash at the beginning. Ditto for the list of stuff to unpin.

      # constants
      $CSIDL_COMMON_PROGRAMS = 0x17 
      $CSIDL_PROGRAMS = 0x2
      $CSIDL_APPDATA = 0x1A
      $CSIDL_WINDOWS = 0x24
      
      $shell = new-object -com "Shell.Application"
      $startMenuProgramsPath = ($shell.NameSpace($CSIDL_COMMON_PROGRAMS)).Self.Path
      $userPinnedItemsPath = ($shell.NameSpace($CSIDL_APPDATA)).Self.Path + '\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar'
      
      # stuff to pin to taskbar - a hash of {folder => (array of files to pin)}
      $itemsToPinToTaskbar = @{
        [System.IO.Path]::Combine($startMenuProgramsPath,'Microsoft Office 2013') = ('Word 2013.lnk','Outlook 2013.lnk')
        # 'c:\Program Files\SomeApp' = ('someapp.exe')
        # etc.
      }
      
      # stuff to pin to start menu - a hash of {folder => (array of files to pin)}
      $itemsToPinToStartMenu = @{
        [System.IO.Path]::Combine($startMenuProgramsPath,'Microsoft Office 2013') = ('Word 2013.lnk','Outlook 2013.lnk')
      }
      
      # stuff to unpin from taskbar
      $itemsToUnpinFromTaskbar = ('Windows Media Player.lnk')
      
      # unpin items from taskbar
      foreach ($file in $itemsToUnpinFromTaskbar) {
        $shell.Namespace($userPinnedItemsPath).Parsename($file).invokeverb('taskbarunpin')
      }
      
      # pin items to taskbar
      foreach ($folder in $itemsToPinToTaskbar.keys) {
        foreach ($target in $itemsToPinToTaskbar[$folder]) {
          $shell.Namespace($folder).Parsename($target).invokeverb('taskbarpin')
        }
      }
      
      # pin items to start menu
      foreach ($folder in $itemsToPinToStartMenu.keys) {
        foreach ($target in $itemsToPinToStartMenu[$folder]) {
          $shell.Namespace($folder).Parsename($target).invokeverb('startpin')
        }
      }