Pin program to start menu using PS in Windows 10

chaitug picture chaitug · Apr 22, 2016 · Viewed 12.7k times · Source

I am trying to pin a program to the start menu in Windows 10

$shell = New-Object -ComObject "Shell.Application"
$Folder = $shell.NameSpace("C:\Test")
$exe = $Folder.ParseName("notepad.exe")
#$exe.Verbs()
$ItemVerbs = $exe.Verbs()

Foreach($ItemVerb in $ItemVerbs)
{
    If($ItemVerb.Name.Replace("&","") -match "Pin to Start")
    {
       $ItemVerb.DoIt()

       Write-Host "Pin to the Start menu sucessfully.+ ""$ItermVerbTxt"" " -ForegroundColor Green
     }
}

After executing this code, i see the success message which means it is finding the required verb.

But i DONT see notepad.exe tile in Start Menu.

Please help

Answer

K.Nickson picture K.Nickson · Mar 2, 2017
function Pin-App {
    param(
        [string]$appname,
        [switch]$unpin
    )
    try {
        if ($unpin.IsPresent) {
            ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ? { $_.Name -eq $appname }).Verbs() | ? { $_.Name.replace('&', '') -match 'From "Start" UnPin|Unpin from Start' } | % { $_.DoIt() }
            return "App '$appname' unpinned from Start"
        }
        else {
            ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ? { $_.Name -eq $appname }).Verbs() | ? { $_.Name.replace('&', '') -match 'To "Start" Pin|Pin to Start' } | % { $_.DoIt() }
            return "App '$appname' pinned to Start"
        }
    }
    catch {
        Write-Error "Error Pinning/Unpinning App! (App-Name correct?)"
    }
}

Pin-App "Outlook 2016"
Pin-App "Google Chrome" 
Pin-App "This PC"