Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Last active February 16, 2024 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaykul/e15c911191999b5bd4f5563d1e84cf97 to your computer and use it in GitHub Desktop.
Save Jaykul/e15c911191999b5bd4f5563d1e84cf97 to your computer and use it in GitHub Desktop.

This is barely worth sharing, but you can, for instance, get everything pinned to the taskbar, and unpin it from the start menu

Get-Application -PinnedToTaskbar | UnpinStart

Huge Caveat: I haven't figured this all out.

  1. I can't figure out a way to get the order of the taskbar items...
  2. Many items don't have the "pin to taskbar" verb when called this way (I don't know why) and you have to do something ridiculous like making a shortcut to them first (thus, the task bar folder) and then pin that.
function Get-ComFile {
param($item)
Write-Host $item.Name -for cyan
foreach ($item in $item.Items()) {
if ($item.IsFolder) {
Get-ComFile $item.GetFolder()
} else { $item }
}
}
function Get-Application {
param(
[string]$Name = "*",
[switch]$PinnedToTaskbar,
[switch]$PinnedToStart,
[guid[]]$Namespace = @(
"4234d49b-0245-4df3-b780-3893943456e1" # Applications
# "1f3427c8-5c10-4210-aa03-2ee45287d668" # User Pinned
)
)
$Application = New-Object -Com Shell.Application
foreach ($ns in $Namespace) {
Get-ComFile ($Application.NameSpace("shell:::{$ns}")) | Where-Object {
($_.Name -like $Name) -and
(!$PinnedToTaskbar -or @($_.Verbs()).Name -replace "&" -eq "Unpin from taskbar") -and
(!$PinnedToStart -or @($_.Verbs()).Name -replace "&" -eq "Unpin from start")
}
}
}
function New-Shortcut {
param (
# Should be a .lnk file path
[string]$Path,
[string]$TargetPath
)
$Shell = New-Object -ComObject WScript.Shell
$Shortcut = $Shell.CreateShortcut($Path)
$Shortcut.TargetPath = $TargetPath
$Shortcut.Save()
}
filter UnpinTaskbar {
@($_.Verbs()).Where{ $_.Name -replace "&" -eq "Unpin from taskbar" }.DoIt()
}
filter UnpinStart {
@($_.Verbs()).Where{ $_.Name -replace "&" -eq "Unpin from Start" }.DoIt()
}
filter PinTaskbar {
@($_.Verbs()).Where{ $_.Name -replace "&" -eq "Pin to taskbar" }.DoIt()
}
filter PinStart {
@($_.Verbs()).Where{ $_.Name -replace "&" -eq "Pin to Start" }.DoIt()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment