PoshCode Logo PowerShell Code Repository

PinnedApplications.psm1 (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1667"></script>download | new post

PowerShell-module with the ability to pin and unpin programs from the taskbar and the Start-menu in Windows 7 and Windows Server 2008 R2.

  1.  # ==============================================================================================
  2.  #
  3.  #
  4.  # NAME: PinnedApplications.psm1
  5.  #
  6.  # AUTHOR: Jan Egil Ring, Crayon
  7.  
  8.  # DATE  : 26.02.2010
  9.  #
  10.  # COMMENT: Module with the ability to pin and unpin programs from the taskbar and the Start-menu in Windows 7 and Windows Server 2008 R2
  11.  #
  12.  # This module are based on the Add-PinnedApplication script created by Ragnar Harper and Kristian Svantorp:
  13.  # http://blogs.technet.com/kristian/archive/2009/04/24/nytt-script-pin-to-taskbar.aspx
  14.  # http://blog.crayon.no/blogs/ragnar/archive/2009/04/17/pin-applications-to-windows-7-taskbar.aspx
  15.  #
  16.  # For more information, see the following blog post:
  17.  # http://blog.crayon.no/blogs/janegil/archive/2010/02/26/pin-and-unpin-applications-from-the-taskbar-and-start-menu-using-windows-powershell.aspx
  18.  #
  19.  # Locale supported: Norwegian, English
  20.  #
  21.  #
  22.  # ==============================================================================================
  23.  
  24.  function Set-PinnedApplication
  25.   {
  26.   <#
  27. .SYNOPSIS
  28. This function are used to pin and unpin programs from the taskbar and Start-menu in Windows 7 and Windows Server 2008 R2
  29. .DESCRIPTION
  30. The function have to parameteres which are mandatory:
  31. Action: PinToTaskbar, PinToStartMenu, UnPinFromTaskbar, UnPinFromStartMenu
  32. FilePath: The path to the program to perform the action on
  33. .EXAMPLE
  34. Set-PinnedApplication -Action PinToTaskbar -FilePath "C:\WINDOWS\system32\notepad.exe"
  35. .EXAMPLE
  36. Set-PinnedApplication -Action UnPinFromTaskbar -FilePath "C:\WINDOWS\system32\notepad.exe"
  37. .EXAMPLE
  38. Set-PinnedApplication -Action PinToStartMenu -FilePath "C:\WINDOWS\system32\notepad.exe"
  39. .EXAMPLE
  40. Set-PinnedApplication -Action UnPinFromStartMenu -FilePath "C:\WINDOWS\system32\notepad.exe"
  41. #>
  42.    [CmdletBinding()]
  43.    param(
  44.       [Parameter(Mandatory=$true)][string]$Action, [string]$FilePath
  45.    )
  46.    
  47.  
  48.  switch ($Action) {
  49.  
  50.  "PinToTaskbar" {
  51.   $PinVerbTask = @{}
  52.  $PinverbTask['En-US'] ="Pin to Taskbar"
  53.  $PinverbTask['Nb-No'] ="Fest til oppgavelinjen"
  54.  
  55.  
  56.     ##get culture
  57.    $culture = $Host.CurrentUICulture.Name
  58.    
  59.   #Check to see if path actually exists
  60.        if(-not (test-path $FilePath)) { write-warning "`nPath does not exist.`n $FilePath `nExiting... `n";  return  }
  61.          
  62.        #this should only be done if a full path is given    
  63.        $path= split-path $FilePath
  64.        #Create shell envir
  65.        $shell=new-object -com "Shell.Application"
  66.        $folder=$shell.Namespace($path)  
  67.        $item = $folder.Parsename((split-path $FilePath -leaf))
  68.      
  69.        $verbs=$item.Verbs()    
  70.            
  71.            foreach($v in $verbs){if($v.Name.Replace("&","") -match $PinVerbTask[$culture]){$v.DoIt()}}
  72.  
  73.  }
  74.  "PinToStartMenu" {
  75.   $PinVerbStart = @{}
  76.   $PinverbStart['En-US'] ="Pin to Start Menu"
  77.   $PinverbStart['Nb-No'] ="Fest til Start-menyen"
  78.  
  79.      ##get culture
  80.    $culture = $Host.CurrentUICulture.Name
  81.  
  82.   #Check to see if path actually exists
  83.        if(-not (test-path $FilePath)) { write-warning "`nPath does not exist.`n $FilePath `nExiting... `n";  return  }
  84.          
  85.        #this should only be done if a full path is given    
  86.        $path= split-path $FilePath
  87.        #Create shell envir
  88.        $shell=new-object -com "Shell.Application"
  89.        $folder=$shell.Namespace($path)  
  90.        $item = $folder.Parsename((split-path $FilePath -leaf))
  91.      
  92.        $verbs=$item.Verbs()    
  93.            
  94.            foreach($v in $verbs){if($v.Name.Replace("&","") -match $PinVerbStart[$culture]){$v.DoIt()}}
  95.  
  96.  }
  97.  "UnPinFromTaskbar" {
  98.    $UnPinVerbTask = @{}
  99.  $UnPinverbTask['En-US'] ="Unpin from Taskbar"
  100.  $UnPinverbTask['Nb-No'] ="Løsne programmet fra oppgavelinjen"
  101.  
  102.    ##get culture
  103.    $culture = $Host.CurrentUICulture.Name
  104.  
  105. #Check to see if path actually exists
  106.               if(-not (test-path $FilePath)) { write-warning "`nPath does not exist.`n $FilePath `nExiting... `n";  return  }
  107.          
  108.        #this should only be done if a full path is given    
  109.        $path= split-path $FilePath
  110.        #Create shell envir
  111.        $shell=new-object -com "Shell.Application"
  112.        $folder=$shell.Namespace($path)  
  113.        $item = $folder.Parsename((split-path $FilePath -leaf))
  114.      
  115.        $verbs=$item.Verbs()    
  116.  
  117.  foreach($v in $verbs){if($v.Name.Replace("&","") -match $UnPinVerbTask[$culture]){$v.DoIt()}}
  118.  }
  119.  "UnPinFromStartMenu" {
  120.    $UnPinVerbStart = @{}
  121.   $UnPinverbStart['En-US'] ="Unpin from Start Menu"
  122.   $UnPinverbStart['Nb-No'] ="Løsne fra Start-menyen"
  123.  
  124.  
  125.      ##get culture
  126.    $culture = $Host.CurrentUICulture.Name
  127.  
  128. #Check to see if path actually exists
  129.               if(-not (test-path $FilePath)) { write-warning "`nPath does not exist.`n $FilePath `nExiting... `n";  return  }
  130.          
  131.        #this should only be done if a full path is given    
  132.        $path= split-path $FilePath
  133.        #Create shell envir
  134.        $shell=new-object -com "Shell.Application"
  135.        $folder=$shell.Namespace($path)  
  136.        $item = $folder.Parsename((split-path $FilePath -leaf))
  137.      
  138.        $verbs=$item.Verbs()    
  139.  foreach($v in $verbs){if($v.Name.Replace("&","") -match $UnPinVerbStart[$culture]){$v.DoIt()}}
  140.  }
  141.  default {Write-Warning "Invalid action specified. Valid actions are: PinToTaskbar, PinToStartMenu, UnPinFromTaskbar, UnPinFromStartMenu"}
  142.  }
  143.  }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me