Optimize Drives With Optimize-Volume
Run defrag or TRIM on a chosen volume with a scriptable cmdlet.
Run Optimize-Volume -DriveLetter C -Defrag -Verbose to defragment the C: volume.
01Command
Command
$ Optimize-Volume -DriveLetter C -Defrag -Verbose02What it does
Optimize-Volume chooses the right operation for the media (defrag for spinning disks, retrim for SSDs) and reports progress as objects. Being a cmdlet, it can be invoked on a schedule or across many machines without opening the Optimize Drives dialog on each one.
03Risk
!Warning: Defragmenting a virtual or SSD volume is unnecessary and can add wear; match the operation to the hardware.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Optimize-VolumeEvidence: Performs defragmentation, trim and other optimization on a volume.
Last verified: 2026-10-13 · Category: System & Settings
06Related solutions
List Volumes and Free Space with Get-Volume
One PowerShell line showing drive letters, labels, filesystems and free space for every volume.
Inspect Physical Disks with Get-Disk
Read-only PowerShell view of each disk's model, bus type, health and partition style.
Grep on Windows: Select-String
Search inside text files and logs with regex, returning file, line number and match.