Powershell: unpin EDGE, Store, Mail and pin Word, Outlook, Excel

There is a verb for the Shell COM objects that handle pinning and unpinning from the taskbar.

function DoUnpin([string]$appname){
    $ErrorActionPreference= 'silentlycontinue'
    ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | Where-Object {$_.Name -eq $appname}).Verbs() | Where-Object {$_.Name.replace('&','') -match 'Unpin from taskbar'} | ForEach-Object {$_.DoIt();}
    $ErrorActionPreference= 'continue'

What this does:
Enumerates the taskbar com object namespace
Finds the $appname
Gets its verbs
Gets the specific "Unpin from Taskbar" verbExecutes the verb.

To use, define the function then run

DoUnpin "Microsoft Edge"

The string you pass it is the direct name the app shows when you right click it on the Taskbar, so to unpin the explorer you would pass it "File Explorer" or for RDP "Remote Desktop Connection".

If you are also looking to pin things, you need to copy over powershell.exe to a new file called explorer.exe and run the Below function.

function DoPin([string]$appname){
    if((Get-Process explorer).count -eq 1){
        Write-Host "Not running as explorer.exe! cannot pin to taskbar!"
    $ErrorActionPreference= 'silentlycontinue'
    ((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();}
    $ErrorActionPreference= 'continue'

So in the end for my company, we use:

Write-Host "Unpinning Edge, Store, and Windows mail"
DoUnpin "Microsoft Edge"
DoUnpin "Store"
DoUnpin "Mail"
# pin IE
Write-Host "Pinning IE, Word, Excel, Outlook (2013 or 2016)"
DoPin "Internet Explorer"
# Pin Word / Excel
DoPin "Word 2013"
DoPin "Excel 2013"
DoPin "Outlook 2013"
DoPin "Word 2016"
DoPin "Excel 2016"
DoPin "Outlook 2016"