Pin and Unpin from Quick Access using PowerShell

CaptnDork

New Member
I am curious if anyone has had any luck unpinning items from Quick Access using PowerShell? I found the following NTLite post and have been trying to figure out the proper code to UNPIN items. SOLVED - AutomaticDestinations Edits For Quick Access

I don't seem to have an issue pinning using:
Code:
$Path = "$($env:USERPROFILE)\Music"
$QuickAccess = New-Object -ComObject shell.application
$TargetObject = $QuickAccess.Namespace("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}").Items() | where {$_.Path -eq "$Path"}
$QuickAccess.Namespace("$Path").Self.InvokeVerb(“pintohome”)

However, I can't seem to get items to UNPIN. I did find the following StackOverflow post that Quick Access contains two "sections": Pinned Items and Frequent Folders. Music and Videos are in the second section, unlike the rest (Desktop, Downloads, Documents, Pictures). So the verb to invoke changes goes from unpinfromhome to removefromhome. Is it possible programmatically add folders to the Windows 10 Quick Access panel in the explorer window?

I have included a text file with the PowerShell code I'm using - just in case I have something messed up in there.

I'd also like to pin/unpin items (shortcuts?) to the taskbar, but I'm wondering if I'll end up with the same problem? (Haven't tried yet - stuck on this, first.)

Any help would be greatly appreciated!
 

Attachments

  • Pin_Unpin_QA.txt
    2.3 KB
My impression is the answer depends on which Windows version are you're running. Some folder items expose Verbs better than others.
Maybe you can list your Windows version, and see if someone knows the answer.
 
garlin Thanks for the response. I am running Win 11 Pro, ver. 10.0.22631 build 22631 (23H2). My NTLite install will be installing the same version.
 
Some quick testing on W11 23H2:
- Pinning or unpinning folders is really slow, because you're sending events thru Explorer.
- Pinning an already pinned folder, makes Explorer unpin it. It's a toggle function.
- There's no API to sort folders in alphabetical order. If you unpin a Folder in the middle of the list, re-pinning it doesn't restore the original position.
- This doesn't touch frequently accessed folders, which is a function of the jumplists.

Code:
$TestFolder = "C:\Users\GARLIN\Downloads\TEST FOLDER"

if (-not (Test-Path $TestFolder)) {
    New-Item $TestFolder -ItemType Directory | Out-Null
}

$objShell = New-Object -ComObject Shell.Application

for ($i = 0; $i -lt 10; $i++) {
    # My Videos
    $objShell.Namespace("shell:::{A0953C92-50DC-43bf-BE83-3742FED03C9C}").Self.InvokeVerb("UnpinToHome")
    # My Music
    $objShell.Namespace("$($env:USERPROFILE)\Music").Self.InvokeVerb("UnpinToHome")
    # Recycle Bin
    $objShell.Namespace("shell:::{645FF040-5081-101B-9F08-00AA002F954E}").Self.InvokeVerb("PinToHome")
    # Test Folder
    $objShell.Namespace($TestFolder).Self.InvokeVerb("PinToHome")
    Start-Sleep 3

    # My Videos
    $objShell.Namespace("shell:::{A0953C92-50DC-43bf-BE83-3742FED03C9C}").Self.InvokeVerb("PinToHome")
    # My Music
    $objShell.Namespace("$($env:USERPROFILE)\Music").Self.InvokeVerb("PinToHome")
    # Recycle Bin
    $objShell.Namespace("shell:::{645FF040-5081-101B-9F08-00AA002F954E}").Self.InvokeVerb("UnpinToHome")
    # Test Folder
    $objShell.Namespace($TestFolder).Self.InvokeVerb("UnpinToHome")
    Start-Sleep 3
}

Remove-Item $TestFolder
 
Some quick testing on W11 23H2:
- Pinning or unpinning folders is really slow, because you're sending events thru Explorer.
- Pinning an already pinned folder, makes Explorer unpin it. It's a toggle function.
- There's no API to sort folders in alphabetical order. If you unpin a Folder in the middle of the list, re-pinning it doesn't restore the original position.
- This doesn't touch frequently accessed folders, which is a function of the jumplists.

Code:
$TestFolder = "C:\Users\GARLIN\Downloads\TEST FOLDER"

if (-not (Test-Path $TestFolder)) {
    New-Item $TestFolder -ItemType Directory | Out-Null
}

$objShell = New-Object -ComObject Shell.Application

for ($i = 0; $i -lt 10; $i++) {
    # My Videos
    $objShell.Namespace("shell:::{A0953C92-50DC-43bf-BE83-3742FED03C9C}").Self.InvokeVerb("UnpinToHome")
    # My Music
    $objShell.Namespace("$($env:USERPROFILE)\Music").Self.InvokeVerb("UnpinToHome")
    # Recycle Bin
    $objShell.Namespace("shell:::{645FF040-5081-101B-9F08-00AA002F954E}").Self.InvokeVerb("PinToHome")
    # Test Folder
    $objShell.Namespace($TestFolder).Self.InvokeVerb("PinToHome")
    Start-Sleep 3

    # My Videos
    $objShell.Namespace("shell:::{A0953C92-50DC-43bf-BE83-3742FED03C9C}").Self.InvokeVerb("PinToHome")
    # My Music
    $objShell.Namespace("$($env:USERPROFILE)\Music").Self.InvokeVerb("PinToHome")
    # Recycle Bin
    $objShell.Namespace("shell:::{645FF040-5081-101B-9F08-00AA002F954E}").Self.InvokeVerb("UnpinToHome")
    # Test Folder
    $objShell.Namespace($TestFolder).Self.InvokeVerb("UnpinToHome")
    Start-Sleep 3
}

Remove-Item $TestFolder

Ok, I thought I understood when I started testing the toggle, but now I'm just confused. Your code uses both UnpinToHome and PinToHome; I assume you got results from the UnpinToHome? UnpinFromHome, UnpinTohome and RemoveFromHome doesn't seem to have an effect on my system. However, the toggle using PinToHome does work to pin/unpin. :rolleyes:

Also, do you know if it's possible to find out if something is already pinned, so it doesn't get unpinned?
 
You can retrieve the array list of currently pinned Folders:
Code:
($objShell.Namespace("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}").Items() | where { $_.IsFolder -eq $true }).Name

Desktop
Downloads
Documents
Pictures
Videos
Music
 
You can retrieve the array list of currently pinned Folders:
Code:
($objShell.Namespace("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}").Items() | where { $_.IsFolder -eq $true }).Name

Desktop
Downloads
Documents
Pictures
Videos
Music

After some more testing I found I was using the wrong CLSID. Instead of using {679F85CB-0220-4080-B29B-5540CC05AAB6} "Quick access," I should have been using {3936E9E4-D92C-4EEE-A85A-BC16D5EA0819} "Frequent Folders." I don't why my PC is not using Quick Access; even if I manually pin a user folder, or any folder, it still only shows in Frequent Folders. Now the pin AND unpin both work appropriately.

Hopefully this info will be helpful to others. If I can get an updated script written, that uses both CLSIDs, I'll post it here.
 
Back
Top