Create ps1 or batch file to execute DSIM and SFC with admin privileges using Task Scheduler

geercom 81 Reputation points
2022-05-03T21:13:44.347+00:00

Thank you for your kind assistance.

I can run DSIM and SFC commands manually. I can create tasks in Task Scheduler. I cannot create a .ps1 or .bat file to run DSIM and SFC commands. Can you guide me?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,117 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. MotoX80 32,716 Reputation points
    2022-05-04T16:38:21.713+00:00

    Please review my reply in this post.

    https://learn.microsoft.com/en-us/answers/questions/833713/application-is-working-fine-when-runned-manually-b.html

    Just use notepad and create a .bat file in some directory that runs whatever program you want to run. Echoing the date time in the bat file can be useful for troubleshooting. In the scheduled task, set it to launch cmd.exe. In the arguments field, point it to the .bat file and whatever log file and folder names you wish to use.

    Set the task to run as the SYSTEM account and check the "Run with highest privileges" box. Run the task and then review the log file to see what it did.

    0 comments No comments

  2. Limitless Technology 39,506 Reputation points
    2022-05-05T07:55:46.56+00:00

    Hello

    Thank you for your question and reaching out.
    I can understand you are having some issues \ queries related to running DISM and SFC command using .bat file

    You can use below .bat file code block to achieve this.


    @Echo OFF
    DISM /Online /Cleanup-Image /RestoreHealth

    Sfc /scannow


    Then save as C:\Temp\MyComp.bat to your desktop

    Then you can configure in your Task Scheduler with path of this .bat file and make sure you also set proper privilege User account to run this .bat file within Task scheduler.

    ----------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--


  3. MotoX80 32,716 Reputation points
    2022-05-05T22:39:03.217+00:00

    which, coincidentally is not where the file is? You use the path to where it is located on the desktop, not the path in this name you gave it, right?

    We have no way of knowing where you saved any file on your PC. So anything that a forum user would post is essentially an example of how to call a .bat file. The actual folder that you put a file in is up to you.