Pin to Start Menu

I’ve been asked to create a script that will automatically populate the start menu with shortcuts from a specific directory. I understand that Microsoft broke this functionality from Windows 8 to Windows 10 but has since fixed it. However, when I try to run my test script it only creates tiles for shortcuts that link to programs from C:\Program Files and ignores any shortcuts from programs outside that location like C:\Windows\System32\calc.exe.

Here’s the script I’m trying to run:

$files = Get-ChildItem "C:\Users\myusername\Desktop" -filter “*.lnk” -name

for ($i = 0; $i -lt $files.Count; $i++) {
(New-Object -ComObject shell.application).Namespace('C:\Users\myusername\Desktop').parsename($files[$i]).invokeverb(‘pintostartscreen’)
}

When I added a line to output the name of the file being processed I got this list:

  • 7Zip.lnk
  • Calculator.lnk
  • Internet Explorer.lnk
  • Notepad++.lnk
  • PerformanceTest.lnk
  • Shutdown.lnk
  • Wordpad.lnk

Even when I attempt to explicitly pin the Calculator shortcut I get nothing.

(New-Object -ComObject shell.application).Namespace('C:\Windows\System32').parsename(‘calc.exe’).invokeverb(‘pintostartscreen’)

and

$shell = new-object -com “Shell.Application”
$folder = $shell.Namespace('C:\Windows\System32\WindowsPowershell\v1.0')
$item = $folder.Parsename(‘powershell.exe’)
$verb = $item.Verbs() | ? {$_.Name -eq ‘Pin to Start Men&u’}
if ($verb) {$verb.DoIt()}

What am I missing? How do I get Windows to cooperate?

Update: I re-ran the single line attempt to pull the Powershell shortcut and it succeeded! But it still blocked the creation of the Calculator and Shutdown shortcuts from C:\Windows\System32.