Window 10 with WSL Task Scheduler task run at Startup/Logon running a PowerShell script which includes WSL bash command fails.

R

Rabi Cherian

Here is the content of PowerShell script I am trying to run via a startup or log on task created via Task Scheduler in Windows 10.


#power shell file saved as autostartsshd.ps1

bash -c 'sudo service ssh start'


This runs fine when run with powershell.

But running from Task Scheduler at log on throws this error:

bash : The term 'bash' 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 D:\ssh_startup\autostartsshd.ps1:2 char:1

+ bash -c 'sudo service ssh start'

+ ~~~~

+ CategoryInfo : ObjectNotFound: (bash:String) [], CommandNotFoundException

+ FullyQualifiedErrorId : CommandNotFoundException


WorkAround: Create a symlink to 32bit bash.exe in SysWOW64

PS C:\Windows\system32> cd ..\SysWOW64\

PS C:\Windows\SysWOW64> New-Item -ItemType SymbolicLink -Name bash.exe -Target c:\Windows\System32\bash.exe


Can this community help file a bug on this issue, so that it can be fixed in future?

Continue reading...
 
Back
Top Bottom