Powershell – How to pin to taskbar using PowerShell

powershelltaskbarwindows 7

How can I pin some programs to taskbar on Windows 7 using
PowerShell? Please explain step-by-step.

And How to modify the following code to pin a folder to
taskbar? For Example

$folder = $shell.Namespace('D:\Work') 

In this path, example named folder.

Best Answer

You can invoke a Verb (Pin to Taskbar) using the Shell.Application COM object. Here's some example code:

http://gallery.technet.microsoft.com/scriptcenter/b66434f1-4b3f-4a94-8dc3-e406eb30b750

The example is somewhat complicated. Here is a simplified version:

$shell = new-object -com "Shell.Application"  
$folder = $shell.Namespace('C:\Windows')    
$item = $folder.Parsename('notepad.exe')
$verb = $item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar'}
if ($verb) {$verb.DoIt()}