Pin Shortcuts to Taskbar


posted by Gerry Bammert
03-11-2012

Downloads: 334
File size: 4.4kB
Views: 1,809

Embed
Pin Shortcuts to Taskbar
  1. <#   
  2. .SYNOPSIS   
  3.     Pin icons to the taskbar or unpin them. 
  4.  
  5. .DESCRIPTION   
  6.     The script may be used in it-environments (e.g. at schools), where users work with a mandatory profile (ntuser.man
  7.     This script pins icons (=shortcuts) to the taskbar. 
  8.     There are two mandatory parameters: <PinIconsFolder> <Action verb> 
  9.     <PinIconsFolder>  That's the folder, where you collect the icons (=shortcuts). 
  10.                       This folder path can be a local path or an unc-path.  
  11.                       This folder might be placed in the user's homefolder, 
  12.                       so the user could manage the additional icons (=shortcuts) in the taskbar himself. 
  13.     <Action verb>     The verb has to be translated to your language. 
  14.                       english:         "Pin to Taskbar" 
  15.                       german:          "An Taskleiste anheften" 
  16.                       your language :  " ....... " 
  17.     You can find the verb in the shortcuts context menu. 
  18.     Because icons on a network-path can't be pinned to the taskbar for security reasons, 
  19.     the script copies the icons to a temporary path: LOCALAPPDATA\PinIcons\*.* 
  20.      
  21. .NOTES   
  22.     File Name      : PinIconsToTaskbar.ps1  
  23.     Author         : Gerry Bammert, 11.03.2012 
  24.     Prerequisite   : PowerShell V2, Windows 7 
  25.     Copyright 2012 : There's no copyright 
  26.                      Use it, modify it ... and post it back              
  27. .LINK   
  28.     Script is published at: 
  29.     http://powershell.com/cs/media/default.aspx  
  30. .EXAMPLE   
  31.     Example 1 
  32.      
  33.     PinIconsToTaskbar.ps1 <PinIconsFolder> <Action verb> 
  34.      
  35.     ==> change the verb to the appropriate version of your language 
  36.      
  37.     English verbs: 
  38.     PinIconsToTaskbar.ps1 "\\server1\homes$\$username\PinIconsFolder" "Pin to Taskbar" 
  39.     PinIconsToTaskbar.ps1 "\\server1\homes$\$username\PinIconsFolder" "Unpin from Taskbar" 
  40.      
  41.     German verbs: 
  42.     PinIconsToTaskbar.ps1 "\\server1\homes$\$username\PinIconsFolder" "An Taskleiste anheften" 
  43.     PinIconsToTaskbar.ps1 "\\server1\homes$\$username\PinIconsFolder" "Von Taskleiste lösen" 
  44.  
  45. .EXAMPLE     
  46.     Example 2 
  47.      
  48.     PinIconsToTaskbar.ps1 <PinIconsFolder> <Action Verb> 
  49.      
  50.     ==> change the verb to the appropriate version of your language 
  51.      
  52.     English verbs: 
  53.     PinIconsToTaskbar.ps1 "Path to the PinIconsFolder" "Pin to Start Menu" 
  54.     PinIconsToTaskbar.ps1 "Path to the PinIconsFolder" "Unpin from Start Menu" 
  55.      
  56.     German verbs: 
  57.     PinIconsToTaskbar.ps1 "Path to the PinIconsFolder" "An Startmenü anheften" 
  58.     PinIconsToTaskbar.ps1 "Path to the PinIconsFolder" "Von Startmenü lösen"     
  59. #> 
  60.  
  61.  
  62. param([string]$PinIconsFolder = $(Throw "Missing path to <PinIconsFolder>!"), 
  63.       [string]$ActionVerb = $(Throw "Missing ActionVerb e.g. `"Pin to taskbar`"")) 
  64.  
  65. ###### Test-Code ################################################### 
  66. # # param([string]$PinIconsFolder = "\\127.0.0.1\d$\temp\PinIcons", 
  67. # #      [string]$ActionVerb = "Von Taskleiste lösen") 
  68.         
  69.  
  70. function Add-IconToTaskbar 
  71. {   
  72.     param([Parameter(ValueFromPipelineByPropertyName=$true)]   
  73.     [Alias('LinkPath')]   
  74.     [Alias('FileName')]   
  75.     $Path
  76.     begin 
  77.     
  78.         $shell = New-Object -ComObject Shell.Application 
  79.     }   
  80.     process 
  81.     {   
  82.         $parent = Split-Path $Path   
  83.         $child = Split-Path $Path -Leaf   
  84.         $folder = $shell.NameSpace($parent)   
  85.         $file = $folder.ParseName($child
  86.         $allVerbs = $file.Verbs() 
  87.         foreach ($verb in $allVerbs
  88.         
  89.             $verbname = ($verb.name).Replace("&",""
  90.             if ($verbname -eq $ActionVerb
  91.             
  92.                 $verb.DoIt() 
  93.             
  94.         
  95.     }   
  96. }  
  97.  
  98. ######################################################################### 
  99. ##    MAIN PROGRAM 
  100. ######################################################################### 
  101.  
  102. ##### Code for testing different paths ############  
  103. #$PinIconsFolder = "D:\temp\PinIcons" 
  104. #$PinIconsFolder = "\\127.0.0.1\d$\temp\PinIcons" 
  105. ##### Code for testing different verbs ############ 
  106. #$ActionVerb = "An Taskleiste anheften" 
  107.  
  108. $LocalAppData = (Get-ChildItem ENV:LOCALAPPDATA).value 
  109. $tempPinIconsFolder = $LocalAppData + "\PinIcons" 
  110. if (!(Test-Path ($tempPinIconsFolder))) 
  111.     New-Item -path $tempPinIconsFolder -type directory 
  112. $count =
  113. $PinIcons = Get-Childitem -path $PinIconsFolder 
  114. $count = $PinIcons.Count 
  115. if ($count -gt 0) 
  116.     foreach ($icon in $PinIcons
  117.     
  118.         Copy-Item $icon.Fullname $tempPinIconsFolder -Force 
  119.     
  120.     $tempPinIcons = Get-Childitem -path $tempPinIconsFolder 
  121.     foreach ($icon in $tempPinIcons
  122.     
  123.         $ic = $icon.FullName 
  124.         Add-IconToTaskbar $ic 
  125.     

Help ==> Get-Help .\PinIconsToTaskbar.ps1 -Full
The script may be used in it-environments (e.g. at schools), where users work with a
mandatory profile (ntuser.man)
This script pins icons (=shortcuts) to the taskbar.

.NOTES
File Name      : PinIconsToTaskbar.ps1
Author         : Gerry Bammert, 11.03.2012
Prerequisite   : PowerShell V2, Windows 7
Copyright 2012 : There's no copyright, use it, modify it ... and post it back

Help ==>         Get-Help .\PinIconsToTaskbar.ps1 -Full

The script may be used in it-environments (e.g. at schools), where users work with a
mandatory profile (ntuser.man)

This script pins icons (=shortcuts) to the taskbar.

There are two mandatory parameters: <PinIconsFolder> <Action verb>
<PinIconsFolder> That's the folder, where you collect the icons (=shortcuts).
This folder path can be a local path or an unc-path.
This folder might be placed in the user's homefolder,
so the user could manage the additional icons (=shortcuts) in the taskbar himself.
<Action verb> The verb has to be translated to your language.
english: "Pin to Taskbar"
german: "An Taskleiste anheften"
your language : " ....... "

You can find the verb in the shortcuts context menu.
Because icons on a network-path can't be pinned to the taskbar for security reasons,
the script copies the icons to a temporary path: LOCALAPPDATA\PinIcons\*.*

.NOTES

File Name      : PinIconsToTaskbar.ps1
Author         : Gerry Bammert, 11.03.2012
Prerequisite   : PowerShell V2, Windows 7
Copyright 2012 : There's no copyright, use it, modify it, enhance it ... and post it back

.LINK

Script is published at:
http://powershell.com/cs/media/default.aspx

.EXAMPLE

Example 1

 

PinIconsToTaskbar.ps1 <PinIconsFolder> <Action verb>
==> change the verb to the appropriate version of your language

 

English verbs:
PinIconsToTaskbar.ps1 "\\server1\homes$\$username\PinIconsFolder" "Pin to Taskbar"
PinIconsToTaskbar.ps1 "\\server1\homes$\$username\PinIconsFolder" "Unpin from Taskbar"

 

German verbs:
PinIconsToTaskbar.ps1 "\\server1\homes$\$username\PinIconsFolder" "An Taskleiste anheften"
PinIconsToTaskbar.ps1 "\\server1\homes$\$username\PinIconsFolder" "Von Taskleiste lösen"

.EXAMPLE

Example 2

 

PinIconsToTaskbar.ps1 <PinIconsFolder> <Action Verb>
==> change the verb to the appropriate version of your language

English verbs:
PinIconsToTaskbar.ps1 "Path to the PinIconsFolder" "Pin to Start Menu"
PinIconsToTaskbar.ps1 "Path to the PinIconsFolder" "Unpin from Start Menu"

 

German verbs:
PinIconsToTaskbar.ps1 "Path to the PinIconsFolder" "An Startmenü anheften"
PinIconsToTaskbar.ps1 "Path to the PinIconsFolder" "Von Startmenü lösen"

 

 

 

 

 

Comments

Gerry Bammert wrote re: Pin Shortcuts to Taskbar
on 03-11-2012 3:50 PM

That's ok.

Copyright 2012 PowerShell.com. All rights reserved.