Skip to content

Instantly share code, notes, and snippets.

@pauljnav
Created July 18, 2025 11:59
Show Gist options
  • Save pauljnav/61ab057d2ac50dbd87c0d829936c2b8f to your computer and use it in GitHub Desktop.
Save pauljnav/61ab057d2ac50dbd87c0d829936c2b8f to your computer and use it in GitHub Desktop.
Pins or unpins a folder from Windows Quick Access (Home)
function Set-QuickAccessItem
{
<#
.SYNOPSIS
Pins or unpins a folder from Windows Quick Access (Home).
.DESCRIPTION
Uses the Shell COM object to pin or unpin a folder from Quick Access.
Automatically checks the current pin state to avoid unintended toggling.
.EXAMPLE
Set-QuickAccessItem -Path "C:\Projects" -Unpin
Unpins the folder C:\Projects from Quick Access.
.EXAMPLE
Set-QuickAccessItem -Path "C:\Projects"
Pins the folder C:\Projects to Quick Access.
.NOTES
Verbose output is available with -Verbose.
.LINK
Inspired By Dr. Scripto https://devblogs.microsoft.com/scripting/use-powershell-to-work-with-windows-explorer/
#>
[CmdletBinding()]
param (
# The full path to the folder to pin or unpin.
[Parameter(Mandatory,Position=0)]
[string]$Path,
# If specified, the folder will be unpinned from Quick Access if it is currently pinned.
[switch]$Unpin
)
if (-not (Test-Path $Path)) {
Write-Verbose "The specified path does not exist: $Path"
return
}
try {
$shell = New-Object -ComObject shell.application
$quickAccessGUID = 'shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}'
$quickAccessItems = $shell.Namespace($quickAccessGUID).Items()
$resolvedPath = (Get-Item $Path).FullName
$isPinned = $quickAccessItems | Where-Object { $_.Path -eq $resolvedPath }
if ($PSBoundParameters.ContainsKey('Unpin') ) {
if ($isPinned) {
# unpin
$shell.Namespace($Path).Self.InvokeVerb("pintohome")
Write-Verbose "Unpinned from Quick Access"
}
} else {
if (-not $isPinned) {
# pin
$shell.Namespace($Path).Self.InvokeVerb("pintohome")
Write-Verbose "Pinned to Quick Access"
}
}
} catch {
Write-Verbose "Error while modifying Quick Access: $_"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment