[SOLVED] How to Make a chkdsk Batch Script?

Appletax

Well-Known Member
Reaction score
348
Location
U.P. of Michigan
I am finding lots of different methods.

So far, I am liking this:


echo y | chkdsk C: /f /r -- f = fix errors, r = recovery data in bad sectors
shutdown /r /t 0 -- r = restarts the computer after shutting down, t = time in seconds


Put into Notepad > Save As > Filename: chkdsk.bat & Save as type: All Files.

echo y "pipes" the letter y into chkdsk to say yes to the prompt asking if you want it to run the next time Windows is started.

Seems odd to have echo y come before chkdsk ??

After 0 seconds (immediately), shutdown the computer, then restart it.
 
Last edited:
I wouldn't bother with the echo y bit.

All of these utilities can be force run on restart with the right switch, which in this case, I believe, is the /offlinescanandfix switch which can only run on an online disk once it goes offline, and that happens only on restart.

There are lots of chkdsk batch examples out there. A quick look-see should confirm.
 
I wouldn't bother with the echo y bit.

All of these utilities can be force run on restart with the right switch, which in this case, I believe, is the /offlinescanandfix switch which can only run on an online disk once it goes offline, and that happens only on restart.

There are lots of chkdsk batch examples out there. A quick look-see should confirm.

Repair-Volume - the PowerScript replacement for 'chkdsk'

Cool, an upgraded version that works in PowerShell!

I made this:


Repair-Volume -DriveLetter C -FileSystemLabel WINRE_DRV SYSTEM_DRV -OfflineScanAndFix


-OfflineScanAndFix takes the system offline and performs a scan and repair of the volumes.

-DriveLetter C tells it to do this to Local Disk ( C: )

-FileSystemLabel WINRE_DRV SYSTEM_DRV tells it do to this to these two volumes that do not have drive letters (they are created by default when installing Windows)



Question: should I be be doing this instead? -FileSystemLabel WINRE_DRV -FileSystemLabel SYSTEM_DRV

Question 2: with chkdsk, I have it do /f to repair the filesystem and have it do /r to recover data in bad sectors. Repair-Volume repairs the filesystem, but does it also recover data in bad sectors?

Question 3: is there a way to just have it repair the entire drive without specifying drive letters and volume labels?



Can put into Notepad > Save As > Filename: Repair-Volume Script.ps1 & Save as type: All Files

Or use Windows' built-in PowerShell script making program: Windows PowerShell ISE.

You may need to do this: View > Show Script Pane.

Save as PowerShell Files or PowerShell Scripts (needs to have the .ps1 file extension).

The .PS1 extension is to PowerShell scripts as .BAT extension is to Command Prompt scripts.
 
Last edited:
Repair-Volume - the PowerScript replacement for 'chkdsk'

Cool, an upgraded version that works in PowerShell!

I made this:


Repair-Volume -DriveLetter C -FileSystemLabel WINRE_DRV SYSTEM_DRV -OfflineScanAndFix


-OfflineScanAndFix takes the system offline and performs a scan and repair of the volumes.

-DriveLetter C tells it to do this to Local Disk (C:)

-FileSystemLabel WINRE_DRV SYSTEM_DRV tells it do to this to these two volumes that do not have drive letters (they are created by default when installing Windows)



Question: should I be be doing this instead? -FileSystemLabel WINRE_DRV -FileSystemLabel SYSTEM_DRV

Question 2: with chkdsk, I have it do /f to repair the filesystem and have it do /r to recover data in bad sectors. Repair-Volume repairs the filesystem, but does it also recover data in bad sectors?

Question 3: is there a way to just have it repair the entire drive without specifying drive letters and volume labels?



Can put into Notepad > Save As > Filename: Repair-Volume Script & Save as type: All Files

Or use Windows' built-in PowerShell script making program: Windows PowerShell ISE.

You may need to do this: View > Show Script Pane.
Quick aside. The .PS1 extension is to PowerShell scripts as .BAT extension is to Command Prompt scripts.
 
Cannot get the PowerShell script to run.

I'd advise you to keep trying. I still find PowerShell and its syntax a grand PITA compared to Command Prompt. It's so freakin' verbose!

But, eventually, Command Prompt will go away. I may be dead before it does, but the shift by Microsoft toward PowerShell is unmistakable, and I don't think they're going to backport a number of things that have been introduced in PowerShell to Command Prompt.

It behooves all of us in this business to try, even if it's slowly, to get a grip on PowerShell. I'm certainly not any expert because I know how to do so much of what I commonly want to do in Command Prompt. But, I have been playing with PowerShell scripts because I know I need to.
 
Back
Top