0

I have a scheduled Task where an Admin Command Prompt opens up and runs SFC and DISM. Here are the actions I entered in the "Action" tab of Task Scheduler:

Program/script: %windir%\system32\cmd.exe

Add Arguments (optional) /k Dism.exe /online /Cleanup-Image /StartComponentCleanup&&sfc/scannow&&Dism /Online /Cleanup-Image /RestoreHealth&&sfc/scannow

Below is the exported XML file from my scheduled task:

2015-08-13T22:47:14.859563 RAT-COMPUTER\RAT Performs a complete system file check with SFC and DISM twice. \System File Check & Repair 2015-08-17T12:00:00 true 1 S-1-5-21-4275024122-2477020419-317910845-1001 InteractiveToken HighestAvailable IgnoreNew false true true true true true false true true false false false true true PT72H 7 PT5M 3 %windir%\system32\cmd.exe /k Dism.exe /online /Cleanup-Image /StartComponentCleanup&&sfc/scannow&&Dism /Online /Cleanup-Image /RestoreHealth&&sfc/scannow

I tried to run exactly the same scheduled task now on Powershell but with no luck. What do I need to do to "translate" this from command prompt into powershell in the Task Scheduler?

  • Why do you want to run this command through powershell rather than cmd? if you're not going to use powershell commands, there will be no gain into using powershell over command prompt. – LPChip Aug 21 '15 at 11:27
  • Let's say an older (and supposedly wiser) relative of mine insists that Powershell is superior and will replace one day good ol' command prompt and also thinks tasks initated by powershell work faster. – Liam Gutierrez Aug 27 '15 at 7:12
  • I disagree with this. If one day powershell will replace command prompt, it will be in a different operating system, thus you'll need to recreate the task anyway. And powershell being faster than cmd? unlikely. Maybe if you actively use powershell commands vs regular commands, yes. but your script is not changing that. – LPChip Aug 27 '15 at 7:50
0

If it's working in cmd there isn't really any reason to switch to PowerShell but in case you eventually need to run a task in PowerShell:

Program: %windir%\system32\WindowsPowerShell\v1.0\powershell.exe

Arguments: -command Dism /online /Cleanup-Image /StartComponentCleanup&&sfc/scannow&&Dism /Online /Cleanup-Image /RestoreHealth&&sfc/scannow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.