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
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