Having an issue with some PowerShell. Basically I am trying to remove certain Taskbar shortcuts based on the shortcuts path/exe file.
The following code I have gets the pinned shortcuts and their name from the AppData folder:
Function Get-TaskbarShortcuts
{
Begin{
Clear-Host
$Path = "C:\Users\username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
$x=0
} # End of Begin
Process
{
$TaskbarShortcuts = Get-ChildItem $Path -Recurse -Include *.lnk
ForEach($ShortCut in $TaskbarShortcuts)
{
$Shell = New-Object -ComObject WScript.Shell
$Properties = @{
ShortcutName = $Shortcut.Name
LinkTarget = $Shell.CreateShortcut($Shortcut).targetpath
}
New-Object PSObject -Property $Properties
$x ++
Write-Host $ShortCut
} #End of ForEach
[Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
} # End of Process
End{}
}
I need to amend this code to remove certain shortcuts...say for example, a user has pinned 'C:\Windows\notepad.exe' but called the shortcut Name something odd. How would I remove the actual pin from the taskbar (not just delete the shortcut file)?
Deleting the shortcut from the "C:\Users\username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" leaves the icon on the taskbar but in an unusable state and clicking it pops up an error that it doesn't exist and asks if you want to remove it. I'm guessing that this is what you want to avoid.
There doesn't seem to be a simple way to do this, but there's a Module available in the TechNet Script Center that does the trick:
Pin and unpin applications from the taskbar and Start-menu