Free to Defragment Hard Drive with Command Prompt or Powershell

Preparation before Disk Defragment

Before disk defragment, you need to do something for preparation.

1. Make sure that the disk partition has at least 15% free space in order to complete a defragment of a disk partition. If the available space on the partition you want to defrag is less than 15%, it can only defrag only a part of fragments. You can delete some unnecessary files, move files to another partition or free up disk space to get more free space on the partition.

2. It is necessary to analyze the disk drive to see if it needs to be defragmented. If system reports that there is no need to defragment the drive, you had better not perform disk defragment.

Part1: Defragment Disk Partition with Command Prompt

To defragment disk partition with Command Prompt, you can follow the steps below:

Step1. Run Command Prompt on your computer with admin privilegesstart cmd

The methods to access command line are different on various Windows operating system.

Step2. Type defrag D: /o if you want to defrag D drive.

defragment partition

For example:

  • defrag c: /o is to defrag c drive
  • defrag E: /o is to defrag E drive...

Note: /o means to optimize a disk partition.

Option: You may use defrag c: /a at first, and then defrag c: /o

Step1: defrag c: /a to analyze the c drive at first, and then it would tell whether it's recommend to start a defragment.

Step2: defrag c: /o to optmize a drive.

Or you may use the following cmd to defrag a drive.

Type defrag /? or defrag.exe plus the appropriate parameters (e.g. defrag.exe c: /a) to analyze or defrag the partition you need to defragment.

You can type defrage.exe to show list of command line parameters, and then you can type a proper one based on your needs.

defragment from cmd

List of command line parameters:

  • parameters: Meaning of different parameters
  • Volume: Specifies the drive letter or the mount point path of the volume to be defragmented or analyzed
  • defrag.exe -c: Use defrag.exe to defragment all volumes on your computer
  • defrag.exe c: -a: Use defrage.exe to analyze the C: drive
  • defrag.exe c: -r: Use defrage.exe to perform a partial defragmentation which attempt consolidates only the fragments that are smaller than 64MB.
  • defrag.exe c: -w: Use Defrage.exe to perform a full defragment
  • defrag.exe c: -f: Use defrage.exe to force the defragment even when the free space is less than 15% on the C partition
  • defrag.exe c: -v: Use defrage.exe to show detailed analysis and defragmentation output

The c: in the list above refers to the C drive, you can replace c: with any drive letter else on your computer.

Part2: Defrag hard drive using powershell

Step1: Open Windows PowerShell as administrator, and type the following command to analyze your drive. Look at the bottom of the output, it will advise whether or not you need to defrag the drive.
Optimize-Volume -DriveLetter D -Analyze -Verbose

defragment from cmd

And it will tell you: It is recommended that you defragment this volume.

defragment from cmd

Step2: Defrag your drive with the following Powershell command

Optimize-Volume -DriveLetter D -Defrag -Verbose

defragment from cmd

Defrag SSD using Powershell Command

Does defrag an SSD work?

Truth: SSD defragging can cause performance issues and even reduce the life of the SSD. You may use the trim command to erase unused blocks which are no longer in use:
Optimize-Volume -DriveLetter D -ReTrim -Verbose

defragment from cmd

CMD Says Do Not Need to Defragment Hard Drive

If you run CMD to analyze the hard drive and it says there is no need to defragment the selected drive, you had better stop defragmenting it. You usually receive this message when type defrag.exe x: -a command to analyze the selected drive (x: refers to the partition you want to defrag)

no need to defragment

If you receive this message, it means that there is no fragment on the partition. So you do not need to defragment this drive.

Free to Defrag Hard Disk with Software

IM-Magic Partition Resizer is a free partition magic tool which enables you to defrag hard disk with following two steps:

Step1. Right click the partition you want to defrag and select "Defragment" option.

defragment partition

Step2. Confirm to defrag the selected volume

confirm defragement

==> If you want to look for some other methods to defrag hard disk, please go to this page – Free to defragment hard drive on Windows computer>>

Download Proper Version of IM-Magic Partition Resizer

For Windows 11/10/8/7/Vista/XP/2000 ==> Download IM-Magic Partition Resizer Free

For Windows Server All versions ==> Download IM-Magic Partition Resizer Server

Do I Need to Defrag Disk?

There are different methods to defrag hard drive, while Command Prompt is one of them for disk defragment.

When a hard drive contains too many fragments, it could have influence on the performance of the hard disk and slow down your computer. Defragmenting is a process to analyze the disk partition and defragment fragments in order to recover some disk space and improve the performance of your disk. Since data is written randomly to different clusters on a hard disk, there is no way to avoid hard disk fragments. Therefore, it is necessary to regularly defrag hard disk in order to improve performance.

More Related Articles You May Like

Related Product