none
VBS doesn't run PS1 in task scheduler RRS feed

  • Question

  • Hello,

    I have two scripts. VBS:

    set shell = wscript.createobject("wscript.shell")
    shell.run "powershell -file .\test.ps1",0,false

    PS1:

    echo "Hello Universe!" > c:\bin\test.txt

    If I run VBS script from CMD or PowerShell (not as an Admin) - it works. But when I put VBS into Task in the scheduler - it doesn't work:


    A few months ago (maybe a Year ago) such scheduled task was working.

    Thank you in advance.


    • Edited by Anahaym Monday, February 18, 2019 2:49 PM
    Monday, February 18, 2019 2:44 PM

Answers

All replies

  • solved:

    • Marked as answer by Anahaym Monday, February 18, 2019 3:07 PM
    Monday, February 18, 2019 3:07 PM
  • Do it like this.

    A better solution would be to not use VBS at all. Have the task invoke Powershell.exe and point the arguments to the PS1 file. 


     
    Monday, February 18, 2019 3:22 PM

  • A better solution would be to not use VBS at all. Have the task invoke Powershell.exe and point the arguments to the PS1 file. 

    In my case it isn't. because this VBS not only runs the PS1 script but also does something else ;)
    Monday, February 18, 2019 3:36 PM
  • In scheduled tasks you should always use the full path.

    shell.run "powershell -file c:\bin\test.ps1",0,false


    \_(ツ)_/

    Monday, February 18, 2019 3:43 PM
  • In scheduled tasks you should always use the full path.

    shell.run "powershell -file c:\bin\test.ps1",0,false


    \_(ツ)_/

    Yes, I did it (it was the initial script), but it didn't work.
    Monday, February 18, 2019 3:50 PM
  • You also cannot use relative paths in a PS1 script if you want it to be accessed from anywhere.  You can use $PsScriptRoot to add the path that the script is running from.

    These are basic scripting issues. The use of dotted relative paths is just a convenience for typing at a prompt.


    \_(ツ)_/

    Monday, February 18, 2019 3:54 PM
  • jrv now everything is fine. thank you!
    • Edited by Anahaym Monday, February 18, 2019 4:06 PM
    Monday, February 18, 2019 4:06 PM