-1

I have a Powershell script that runs in Windows11 every time a computer loads, to pin a folder to Quick Access. It is based on this thread.

It works, however if the user already had the folder pinned, it will remove the folder instead of leaving it in place. Essentially it acts as a toggle.

I've looked around for some documentation on the InvokeVerb() method but have't found anything clear yet. I would have thought "pintohome" would just leave the pinned folder in place if already there.

Any idea why this is happening? Is it a Windows11 thing?

bon_homie
  • 91
  • 3

1 Answers1

1

Slight modification from your provided link: Simply check if the pin already exists.

$QuickAccess = New-Object -ComObject shell.application
$PathToPin = "C:\MyPathToPin"

if(-not ($QuickAccess.Namespace("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}").Items() | ? {$_.Path -eq $PathToPin})){$QuickAccess.Namespace($PathToPin).Self.InvokeVerb("pintohome")}
ejkeep
  • 318
  • 1
  • 6
  • Thank you! The "shell:::..." string is a shortcut for the Quick Access folder? This worked great, although I used the more verbose Where-Object instead of the alias "?". I guess my question as to why this stopped working in Windows 11 after upgrade from 10 still stands, but is moot. It could just be a Windows thing... – bon_homie Apr 11 '23 at 01:24