SOLVED

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

MVP

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

 

21 Replies
Thanks for all your help!

sysnative is the solution. I'm not checking if the OS is 64-bit and then using sysnative is required..

@Daniel_Pineault 

 

Fair enough, though it means your functions will only work on 32-bit Office, since the virtual alias of sysnative only exists for 32-bit processes running on 64-bit Windows (with syswow64 being the alias in the opposite direction of 64-bit process requiring a 32-bit Windows resource).

 

Cheers,

Lain