Ben
Ben

Reputation: 306

Unpin the Microsoft Edge and store taskbar shortcuts programmatically

I setup computers daily and I need to remove the Microsoft Edge and Store taskbar shortcuts.

I am having trouble creating a script and I have searched for other stackoverflow posts but they were not helpful to me.

Does anyone have a script that can unpin the MS Edge and Store taskbar shortcuts?

Upvotes: 8

Views: 17739

Answers (3)

Jon Courtney
Jon Courtney

Reputation: 1

I just wanted to add a Pin-App method based on Judge2020's post:

function Pin-App([string]$appName) {
    ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() |
        Where-Object { $_.Name -eq $appName }
    ).Verbs() |
    Where-Object { $_.Name.Replace('&', '') -match 'Pin to taskbar' } |
    ForEach-Object { $_.DoIt() }
}


Pin-App "Google Chrome"

Upvotes: 0

Judge2020
Judge2020

Reputation: 349

You can unpin taskbar items by running the following PowerShell commands.

function Unpin-App([string]$appname) {
    ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() |
        ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt()}
}

Unpin-App("Microsoft Edge")
Unpin-App("Microsoft Store")

This should work for any application on the taskbar. If the application isn't found, the error InvokeMethodOnNull will be thrown.

What this does:

  • Enumerates the Shell/taskbar COM object namespace
  • Matches the item with the name $appname (in this case, Edge and Store)
  • Gets the verb Unpin from taskbar of that com object
  • Executes the verb to remove it from the taskbar (without having to kill explorer.exe)

Upvotes: 16

user6811411
user6811411

Reputation:

Very nice solution from Judge2020, +1

  • With a RegEx and -match instead of -eq you can unpin several Apps in one run
  • The unpin verbs are localized, in German it's Von "Start" lösen

$appnames = "^Microsoft Edge$|^Store$"
((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | 
  Where-Object{$_.Name -match $appnames}).Verbs() | 
  Where-Object{$_.Name.replace('&','') -match 'Unpin from taskbar|Von "Start" lösen'} | 
  ForEach-Object{$_.DoIt(); $exec = $true}

Upvotes: 6

Related Questions