question

PeizhiYu avatar image
0 Votes"
PeizhiYu asked Anthony-4123 answered

Run powershell script using Task Scheduler

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
1.png (66.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
if you are able to run the script manually with the same parameters as specified on the scheduled task, then most probably you need to reconfigure the task in a proper way. Can you please verify this. Here is a nice guide to use as a reference:

How to Schedule PowerShell Script using Task Scheduler
https://o365reports.com/2019/08/02/schedule-powershell-script-task-scheduler/


(If the reply was helpful please don't forget to upvote or accept as answer, thank you)
Thanks and Regards,
Stoyan





0 Votes 0 ·
IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT commented

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

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes, I can run the script manually.

0 Votes 0 ·

Hi,
In this case it‘s not a powershell issue. Please check the OS version and add the corresponding tag.
Best Regards,
Ian

0 Votes 0 ·

how should I to add the corresponding tag?

0 Votes 0 ·
Show more comments
MotoX80 avatar image
0 Votes"
MotoX80 answered

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CesarContreras-1660 avatar image
0 Votes"
CesarContreras-1660 answered CesarContreras-1660 edited

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.

  2. 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.





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Anthony-4123 avatar image
1 Vote"
Anthony-4123 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.