Forum Discussion
Get-StartApps : The term 'Get-StartApps' is not recognized as the name of a cmdlet, function, script
- Feb 11, 2024
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.exeCheers,
Lain
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.
Import-Module : The specified module 'StartLayout' was not loaded because no valid module file was found in any module
directory.
At line:1 char:1
+ Import-Module StartLayout;$ToastHeader = New-BTHeader -Title 'Plannin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (StartLayout:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
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:225
+ ... \Databases\icons\agenda-153555_640.png' -AppId (Get-StartApps | Where ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-StartApps:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
- Feb 10, 2024Try this?
CreateObject("WScript.Shell").Run "powershell -executionpolicy RemoteSigned -noprofile -command ""Install-Module StartLayout; Install-Module StartLayout ; Get-StartApps | Where-Object name -eq 'Notepad';Start-Sleep -Seconds 8;""", 1, True- Feb 10, 2024but then that requires Admin rights, so that's a no go.
Really odd, that it works fine in the ISE, but not run from cmd...- LainRobertsonFeb 10, 2024Silver Contributor
I have zero experience with Office automation - that's totally not my area, so forgive my ignorance on that front.
However, the only reason a module would not be found is if the search path environment variable does not contain a match, which in this scenario is odd since it's a module that ships with Windows itself.
I've had a strong aversion to anything "per user" for 24-odd years now (courtesy of wearing an application packaging hat many years ago) meaning all my modules are installed per machine, which leaves me unable to replicate this issue - not that I potentially could given this is a pre-canned module.
That leaves me unsure on what the issue could be. But, after availing myself on how to put something very basic (no pun intended) together in VBA, I'd be curious to see what the output for these three functions is in your environment:
VBA code in Excel
Function GetPSVersion() Set Process = CreateObject("WScript.Shell").Exec("powershell.exe -Command ""& { [PSCustomObject] $PSVersionTable | Write-Host; }""") Do While Process.Status = 0 Application.Wait (Now() + TimeValue("0:00:01")) Loop GetPSVersion = Process.StdOut.ReadAll End Function Function GetModulePaths() Set Process = CreateObject("WScript.Shell").Exec("powershell.exe -Command ""& { (Get-Module -ListAvailable -Name StartLayout).ModuleBase; }""") Do While Process.Status = 0 Application.Wait (Now() + TimeValue("0:00:01")) Loop GetModulePaths = Process.StdOut.ReadAll End Function Function GetPath() Set Process = CreateObject("WScript.Shell").Exec("powershell.exe -Command ""& { $env:Path.Split(\"";\"", [System.StringSplitOptions]::RemoveEmptyEntries); }""") Do While Process.Status = 0 Application.Wait (Now() + TimeValue("0:00:01")) Loop GetPath = Process.StdOut.ReadAll End FunctionOutput
This is obviously from my own client.
Cheers,
Lain