question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pwsh.exe executable does not work in Windows Task Scheduler

See original GitHub issue

Hi,

I was using powershell.exe for my current script in task scheduler without problems. I installed Powershell 7.1 through Microsoft Store and when I look at add/remove files I see it as installed. When I changed the program/script to pwsh.exe I started getting file not found errors, reading issue #13302, I thought it was the path that was the problem. When I run where pwsh.exe I get 2 paths:

1) C:\Program Files\WindowsApps\Microsoft.PowerShell_7.1.0.0_x64__8wekyb3d8bbwe\pwsh.exe
2) C:\Users\user1\AppData\Local\Microsoft\WindowsApps\pwsh.exe

Looking at user1’s Path, I see no 2, which provides why it runs interactively. Looking at system path, none are listed, which is why task scheduler fails. I am not clear on how to solve this. if I enter no 1 in system’s path, whenever application is automatically upgraded, it will become invalid and script will fail. if I enter no 2, it depends on user1 being available which I think is the best approach.

Could somebody propose the best action here?

Environment data

Name Value


PSVersion 7.1.0 PSEdition Core GitCommitId 7.1.0 OS Microsoft Windows 10.0.18363 Platform Win32NT


Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
doctordnscommented, Dec 22, 2020

That is a remarkably silly conclusion in my view.

I have Pwsh 7.1 installed on a bunch of domain servers and all can use it just fine even with task scheduler. Try using the Install-PowerShell script on GitHub. Get it at https://github.com/PowerShell/PowerShell/blob/master/tools/install-powershell.ps1. If you have to install it from the store, re-read the post avoce from @jborean93 which shows how you can resolve your issue.

IMHO, the store is for consumer apps on Windows client devices. If you want to manage a domain and do grown up stuff, install PowerShell 7 from the real source. Chocolately is a non-supported repository. If support matters, use a more supported approach.

<div> GitHub</div><div>PowerShell/PowerShell</div><div>PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.</div>
2reactions
erenturkmcommented, Dec 22, 2020

Basicly what you are saying, If you want to use PS 7.x from Microsoft store (that automatically upgrades itself) you can’t use it from Task Scheduler. <sigh> back to chocolatey then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pwsh.exe executable does not work in Windows Task ...
If the Task Scheduler cannot find pwsh.exe, there is an issue with your PATH environment variable. I would guess that the home folder...
Read more >
Powershell script not working through Task Scheduler
In the Scheduler I found that the Task starts and finishes but the script does not run. I even added the command below...
Read more >
PS 7.1 from Store; how-to call pwsh from Task Scheduler?
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...
Read more >
Cannot run .exe from Task Scheduler same as in ...
Try running the Task Scheduler 'interactive` for 'When running the task, use the following user account` and also check the box in Task ......
Read more >
PowerShell Core script runs but is not executed by Task ...
When setting the scheduled task, under Action -> Start a Program -> Program/Script. Call powershell and pass the script as the parameter.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found