Using Windows Task Scheduler to run PS1 Script - Getting Error

Welcome Forums General PowerShell Q&A Using Windows Task Scheduler to run PS1 Script - Getting Error

Viewing 2 reply threads
  • Author
    Posts
    • #180971
      Participant
      Topics: 1
      Replies: 0
      Points: 112
      Rank: Participant

      Hello Team,

      I am new to Powershell and hopefully this is a simple enough problem on my end that you can help me solve. I have the PowerShell script build and its running fine when I run it via the Task Scheduler. My issue is that in Task Scheduler I have provided Action to Start Powershell.exe and below Option:

      -ExecutionPolicy Unrestricted -NoExit C:\Backups\Scripts\TSMBackup_Daily.ps1

       

      Due to above I get the below error message:

      Task Scheduler did not launch task "\Daily – Backup" because instance "{0ffb0fe2-b48b-40ba-a97a-08bd1ded01a5}" of the same task is already running.

      Is this due to "-NoExit" defined above? if so is there a way to stop the task once the script is ran?

    • #181034
      Participant
      Topics: 1
      Replies: 11
      Points: 58
      Rank: Member

      Hi,

      Try to kill Powershell.exe in task manager and then run the task scheduler.

    • #181076
      Participant
      Topics: 6
      Replies: 108
      Points: 297
      Helping Hand
      Rank: Contributor

      Definitely sounds like the task is never exiting, so the next one won't start. And yes, I would guess that it is because of the -noexit switch on powershell.exe. That will tell the console to stay open after running the script you passed to it (C:\Backups\Scripts\TSMBackup_Daily.ps1). You should have a powershell.exe process still running if you look at Task Manager, as suggested, and you should be able to run the task after killing that process. In the end, though, you'll want to remove the -noexit switch from the task so that it will exit on it's own.

      For reference: https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/About/about_PowerShell_exe?view=powershell-5.1

Viewing 2 reply threads
  • You must be logged in to reply to this topic.