PS 7.1 from Store; how-to call pwsh from Task Scheduler?

Dick Watson 81 Reputation points
2020-12-11T22:08:06.147+00:00

I have a scheduled task that was running as expected using the GitHub MSI version 7.0.3.

I installed PS 7.1 on Windows 10 via the new Microsoft Store installer. I can open PS 7.1 from start or via "pwsh" from cmd.exe or Windows+R run pwsh. So, it's in my profile's path.

Revising the action of that task to run "pwsh" gets "The system cannot find the file specified. (0x80070002)"

Revising the action of that task to run "C:\Users\myuser\AppData\Local\Microsoft\WindowsApps\pwsh.exe" gets "The file cannot be accessed by the system. (0x80070780)"

Trying to edit the task scheduled action by browsing to the ...WindowsApps\pwsh.exe also gets the "file cannot be accessed" error.

Is the Windows Store install of PowerShell just not setup to be used from a scheduled task?!? Is there another way? Should I just revert to using the GitHub MSIs for PowerShell instead of letting Windows Store keep it current?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,718 questions
0 comments No comments
{count} votes

Accepted answer
  1. Eleven Yu (Shanghai Wicresoft Co,.Ltd.) 10,756 Reputation points Microsoft Vendor
    2020-12-14T08:13:42.97+00:00

    Hi,

    Please be informed that task scheduler cannot directly run a app installed from microsoft store. It is a by-design behavior.

    But you can check below thread where another user posted a similar question. Please refer to Pablo García Lluch's answer to see if it can give you some help.
    https://answers.microsoft.com/en-us/windows/forum/all/open-an-app-from-microsoft-store-using-task/161a547f-6c1f-467d-9944-236a01e91ecf

    Thanks,

    Eleven

    If the Answer is helpful, please click "Accept Answer" and upvote it. Thanks.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Rich Lewis 11 Reputation points
    2022-08-16T16:59:09.157+00:00

    Appreciate this is a zombie thread, but I just discovered that Windows seems to install a kind of shim file for Windows Store apps in %localappdata%\Microsoft\WindowsApps. In here you'll find a pwsh.exe (with a size of 0 bytes!). Putting the path for this into my scheduled task worked.

    Note that you can also find the 'real' pwsh.exe at C:\Program Files\WindowsApps\Microsoft.PowerShell_7.2.6.0_x64__8wekyb3d8bbwe\pwsh.exe. However, as you can see, the path includes the Powershell version number, which of course changes every time an update happens. Which is why my old scheduled task stopped working! Now I've found this new location for the shim, hopefully it will carry on working across an update.

    Good luck!

    2 people found this answer helpful.

  2. Dick Watson 81 Reputation points
    2020-12-14T16:56:22.31+00:00

    So, once again, UWP Apps must also be Gimped Apps. Sad. It's unfortunate that installing the UWP app actually makes using PowerShell harder not easier for this use case.

    I might try scheduling to run task cmd.exe with params "/C start Shell:AppsFolder(some as yet undetermined magic)\pwsh" but initial playing around via Windows+R to see what would work here has not been promising.

    For now, I'll revert to the GitHub .MSI and say thanks but no thanks for the Store installer. Sorry to repeat, but: Sad. And Microsoft wonders why UWP is DEAD...


  3. Dick Watson 81 Reputation points
    2022-08-16T20:06:58.86+00:00

    I've also been succesful just scheduling "pwsh -NoProfile -ExecutionPolicy Bypass -File 'myscript.ps1' -LogResults" and letting PATH find it. It does seem to be running the most recent installed PS version.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.