Hello,
I recently read a blogpost about it there, and I wanted to improve that function, here it comes :
function Pin-Taskbar{ <# .SYNOPSIS This function pin a program to the Windows taskbar. .DESCRIPTION This function uses Shell.Application object. .PARAMETER Item Path to the object to pin. .EXAMPLE Pin-Taskbar -item C:WindowsSystem32mspaint.exe -Verbose .INPUTS .OUTPUTS .NOTES .LINK http://ItForDummies.net #> [cmdletbinding()] Param( [Parameter(Mandatory =$true)] [ValidateScript({Test-Path -Path $_ -PathType Leaf})] [string]$Item ) Write-Verbose -Message "Creating Shell.Application object..." $Shell = New-Object -ComObject "Shell.Application" $ItemParent = Split-Path -Path $Item -Parent $ItemLeaf = Split-Path -Path $Item -Leaf $Folder = $Shell.NameSpace($ItemParent) $ItemObject = $Folder.ParseName($ItemLeaf) $Verbs = $ItemObject.Verbs() try{ Write-Verbose -Message "Trying to pin $ItemLeaf" #$Verb = $Verbs | Where-Object -Property Name -EQ "Pin to Tas&kbar" -ErrorAction Stop #V3 only $Verb = $Verbs | Where-Object {$_.Name -EQ "Pin to Tas&kbar"} -ErrorAction Stop $Verb.DoIt() }catch{Write-Error -Message "Unable to pin !"} } function Unpin-Taskbar{ <# .SYNOPSIS This function unpin a program of the Windows taskbar. .DESCRIPTION This function uses Shell.Application object. .PARAMETER Item Path to the object to unpin. .EXAMPLE unPin-Taskbar -item C:WindowsSystem32mspaint.exe -Verbose .INPUTS .OUTPUTS .NOTES .LINK http://ItForDummies.net #> [cmdletbinding()] Param( [Parameter(Mandatory =$true)] [ValidateScript({Test-Path -Path $_ -PathType Leaf})] [string]$Item ) Write-Verbose -Message "Creating Shell.Application object..." $Shell = New-Object -ComObject "Shell.Application" $ItemParent = Split-Path -Path $Item -Parent $ItemLeaf = Split-Path -Path $Item -Leaf $Folder = $Shell.NameSpace($ItemParent) $ItemObject = $Folder.ParseName($ItemLeaf) $Verbs = $ItemObject.Verbs() try{ Write-Verbose -Message "Trying to unpin $ItemLeaf" #$Verb = $Verbs | Where-Object -Property Name -EQ "Unpin from Tas&kbar" -ErrorAction Stop #V3 only $Verb = $Verbs | Where-Object {$_.Name -EQ "Unpin from Tas&kbar"} -ErrorAction Stop $Verb.DoIt() }catch{Write-Error -Message "Unable to unpin !"} }
You can paste it in a *.psm1 file to create a module, I recommend you to use the “#Requires -version 2” tag at the beginning of the file.
If you need help on how to use the functions, feel free to use :
Get-Help Pin-Taskbar -Full or Get-Help Unpin-Taskbar -Full.
Pingback: Powershell Script – Removing Office 2010 Applications from Taskbar | HitBits.net