Monday, September 8, 2014

3 Line Pin to the TaskBar via PowerShell

So you want to pin some stuff to the user's taskbar quickly and with minimum code.  What do you do?  There are a whole lot of ugly VBS scripts out there and a few powershell scripts as well.  All are pretty fat.  Here is the minimal version of all them:

$Path = @("C:\Windows\system32\notepad.exe","C:\Windows\System32\shutdown.exe")
$Desktop = (New-Object -ComObject Shell.Application).NameSpace(0X0)
Foreach($itemPath in $Path){Foreach($ItemVerb in (($Desktop.ParseName($itemPath)).Verbs())){If($ItemVerb.Name.Replace("&","") -match "Pin to Taskbar"){$ItemVerb.DoIt()}}}

This is 3 lines of love for the taskbar.  If you switch the 'match' to 'Pin to Start Menu' the magic moves to the start menu.  Happy pinning.