Forum Discussion

Daniel_Pineault's avatar
Feb 09, 2024

Get-StartApps : The term 'Get-StartApps' is not recognized as the name of a cmdlet, function, script

I have a command such as

 

(Get-StartApps | Where-Object name -eq 'Notepad').AppId

 

or just simply

 

Get-StartApps

 

which works just fine via PowerShell ISE.

 

I, on the other hand, am trying to run it via VBA in Excel/Access.... and do so by using WScript.Shell

 

CreateObject("WScript.Shell").Run "powershell -executionpolicy RemoteSigned -command ""Get-StartApps | Where-Object name -eq 'Notepad';Start-Sleep -Seconds 8;""", 1, True

 

where I then receive the error :

 

Get-StartApps : The term 'Get-StartApps' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-StartApps | Where-Object name -eq 'Notepad';Start-Sleep -Seconds ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-StartApps:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

 

I can simplify it to bare minimum

 

CreateObject("WScript.Shell").Run "powershell -executionpolicy RemoteSigned -command ""Get-StartApps;Start-Sleep -Seconds 8;""", 1, True

 

and it still returns

 

Get-StartApps : The term 'Get-StartApps' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-StartApps;Start-Sleep -Seconds 8;
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-StartApps:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

 

(The Start-Sleep -Seconds 8; is only there for debugging purposes, the command errs without it being present just the same.)

 

 

I even thought maybe it was a 32-bit vs. 64-bit issue and tried explicitly specifying the PS exe to use

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

 

but it made no difference, both failed the same.

 

Now I've used such an approach to do all sorts of other thing in PS via VBA without issue.  This truly is specifically related to the Get-StartApps CmdLet.  Is there something special about it that makes it not accessible?  Anyone have any ideas?  Maybe an alternate way to retrieve a programs AppId, that's what I'm ultimately after?!

 

Thank you for your help in advance.

 

Daniel

 

  • LainRobertson's avatar
    LainRobertson
    Feb 11, 2024

    Daniel_Pineault 

     

    The only suggestion I have now is replacing your "powershell.exe" statement with a full path alternative of:

     

    C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe

     

    Cheers,

    Lain

  • I've come up with a workaround, still testing, but using the following seems to work

    ((New-Object -ComObject Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | Where-Object { $_.name -like 'Notepad' } ).Path

    but I'd still love to understand why the standard CmdLet doesn't work. Are there others that act in the same manner and should be avoided? How can I identify them so as to not waste countless hours fighting with them?
      • Harm_Veenstra's avatar
        Harm_Veenstra
        MVP

        Get-StartApps is part of the StartLayout module; you could try to import-module StartLayout first.?

        Something like this: (Added -noprofile for possible faster loading)

        CreateObject("WScript.Shell").Run "powershell -executionpolicy RemoteSigned -noprofile -command ""Import-Module StartLayout ; Get-StartApps | Where-Object name -eq 'Notepad';Start-Sleep -Seconds 8;""", 1, True

         


        Please click Mark as Best Response & Like if my post helped you to solve your issue.
        This will help others to find the correct solution easily. It also closes the item.

        If one of the posts was helpful in other ways, please consider giving it a Like.

Resources