Pin to Quick Access with Powershell

So here’s a fun one that saved me buckets of time the other day.

We needed to give our not so tech savvy users easy access to a folder without having to provide directions to them to navigate to the folder.

Now, just like with everything else, there were multiple ways to tackle this problem, but in the end, considering the circumstances around the request, we decided to see if we could pin things to the “Quick access” in windows file manager automagically.

Well, after a little googling around and rummaging through a few Reddit threads, I figured out that we could do this via ComObjects in powershell like so:

1
2
$load_com = new-object -com shell.application
$load_com.Namespace("C:\TestFolder").Self.InvokeVerb("pintohome")

You can change the C:\TestFolder to pretty much any folder on the local machine, as well as network shares.

So, what if I want to UNpin the folder from quick access?

Well, it’s almost as easy as pinning:

1
2
$load_com = New-Object -ComObject shell.application
($load_com.Namespace("shell:::{679F85CB-0220-4080-B29B-5540CC05AAB6}").Items() | Where-Object { $_.path -eq 'C:\TestFolder' }).InvokeVerb("unpinfromhome")

Now, I’m not going to pretend like I’m an expert on what all the commands are doing under the hood, but I do know it works.

So for an example, part of what I’m doing with my script:

1
2
3
4
5
6
7
8
9
$my_path = "C:\TestFolder"
$load_com = New-Object -ComObject shell.application
$quickpin_path = $load_com.Namespace("shell:::{679F85CB-0220-4080-B29B-5540CC05AAB6}").Items() | Select-Object Path
if ($quickpin_path -notcontains $my_path){
    $load_com.Namespace($my_path).Self.InvokeVerb("pintohome")
}
if ($quickpin_path -match [Regex]::Escape($my_path)) {
    Write-Output "Wooo! Already pinned!"
}

Eventually I’d like to pack this all up into a module I can just call with something like Pin-Quick -Path “C:\FilePath”

Leave a Reply

Your email address will not be published. Required fields are marked *