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".