PowerShell Commands for PinnedItem Item to Taskbar (This PC, User's Profile & Disk D:)

Ravishanka Fonseka 0 Reputation points
2023-06-18T02:09:53.2+00:00

I'm looking for a way to have a PowerShell command or script to pin the following 3 icons to the taskbar, I've seen them done from GUI.

"This PC" in Windows 10 & 11
"User's Files" in Windows 10 & 11
"D:" Drive in Windows 10 & 11New-PinnedItem.txt

I prefer to have the scripts separately please, soincasee I only want to execute 1 of them instead of all.


I created the scripts below; it only created in below location.

Module: **Install-Module -Name PinnedItem
**
https://www.powershellgallery.com/packages/PinnedItem/0.2.0.0

%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,688 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
9,847 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,546 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,577 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Khaled Elsayed Mohamed 1,290 Reputation points
    2023-07-24T09:27:28.8733333+00:00

    Hi R F

    Pinning items to the taskbar in Windows 10 and 11 can be achieved using PowerShell by creating a shortcut and then pinning that shortcut to the taskbar. Here's a PowerShell script that does this for "This PC," "User's Files," and the "D:" drive:

    function Create-Shortcut {
        param (
            [string]$TargetPath,
            [string]$ShortcutPath
        )
    
        $WshShell = New-Object -ComObject WScript.Shell
        $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
        $Shortcut.TargetPath = $TargetPath
        $Shortcut.Save()
    }
    
    # Replace the following paths with the appropriate ones for your system
    $ThisPCPath = "C:\Users\your_username\Desktop\ThisPC.lnk"
    $UsersFilesPath = "C:\Users\your_username\Desktop\UsersFiles.lnk"
    $DriveDPath = "C:\Users\your_username\Desktop\DriveD.lnk"
    
    # Create shortcuts for each item
    Create-Shortcut -TargetPath "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" -ShortcutPath $ThisPCPath
    Create-Shortcut -TargetPath "shell:::{59031a47-3f72-44a7-89c5-5595fe6b30ee}" -ShortcutPath $UsersFilesPath
    Create-Shortcut -TargetPath "D:\" -ShortcutPath $DriveDPath
    
    # Pin shortcuts to the taskbar
    $shell = New-Object -ComObject Shell.Application
    $taskbarPath = [System.IO.Path]::Combine([Environment]::GetFolderPath('ApplicationData'), 'Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar')
    
    $shell.Namespace($taskbarPath).Self.InvokeVerb('pindirectory', $ThisPCPath)
    $shell.Namespace($taskbarPath).Self.InvokeVerb('pindirectory', $UsersFilesPath)
    $shell.Namespace($taskbarPath).Self.InvokeVerb('pindirectory', $DriveDPath)
    

    Make sure to replace 'your_username' in the paths with your actual Windows username.

    Please note that the paths to pin items to the taskbar may vary depending on the version of Windows and the user's environment. The script above creates shortcuts on the desktop and then pins them to the taskbar. However, if the desktop is hidden or not accessible, you may need to modify the script to create the shortcuts in a different location that is accessible for pinning.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.