Run powershell script using Task Scheduler

Peizhi_Yu 1 Reputation point
2020-09-14T00:22:07.777+00:00

I have a script that is reset password of the user.

I want to run it use task scheduler every hour once.

But is failed.

The history of scheduler show the task completed.
but the script don't have any out.

This is my action set
24186-1.png

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,553 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Cesar Contreras 21 Reputation points
    2021-09-04T13:47:20.03+00:00

    Several points to troubleshoot:

    1. To confirm if PowerShell command is able to execute and check the results, open a D.O.S. session (cmd.exe) and execute the command and parameters registered on the Scheduled task.

    i.e

    powershell.exe -file "c:\temp\hello.ps1"
    
    C:\Temp>powershell.exe -file "c:\temp\hello.ps1"
    

    Once is confirmed executing correctly try again with the schedule.


    1. In order to have more feedback you can use Start-Transcript / Stop-Transcript commands to log any execution details on a Log file.
      1. Confirm the resources used by your script, for instance if you are using network resources you will need your schedule task to be logged as an user to work.
    4 people found this answer helpful.

  2. Anthony 6 Reputation points
    2021-09-16T19:47:40+00:00

    I don't know if you ever figured it out but from the look of your screenshot you have a forward slash in your arguments for the file path. Windows file paths use backslashes.

    1 person found this answer helpful.
    0 comments No comments

  3. Ian Xue 37,706 Reputation points Microsoft Vendor
    2020-09-14T02:37:33.46+00:00

    Hi,
    Task completed does not mean the script has been executed successfully. Can you run the script manually?
    Best Regards,
    Ian


  4. MotoX80 34,431 Reputation points
    2020-09-14T14:15:51.587+00:00

    Add the Start-Transcript and Stop-Transcript commands to your script and see if it encounters an error.

    powershell-transcript-record-a-session-to-a-text-file

    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.