2

I have encountered a weird problem. I don't know how or why it happened, but it just had happened.

The thing is very simple, I can use Optimize-Volume cmdlet on both PowerShell 7 and Windows PowerShell to defragment my drives without problem, it works properly.

This command works as intended:

Optimize-Volume -DriveLetter D -Analyze -Defrag

Now I don't know the relationship between Defrag.exe and Optimize-Volume cmdlet, but I think they have very similar functions, and defrag.exe seems to have more applications, so I presume Optimize-Volume is a wrapper for defrag.exe.

But this command which does exactly the same thing as the PowerShell command above will not run not matter what:

defrag D: /A /D

It just shows this error message:

An invalid command line option was specified. (0x89000008)

Then it shows its help message.

I have also tried to use the full names of the arguments:

defrag D: /Analyze /Defrag

Result: same error as above.

I have tried to run defrag on PowerShell 7, Windows PowerShell and Command Prompt, and it always shows the above mentioned error message, this phenomenon is perfectly reproducible.

Why defrag.exe keeps complaining about invalid arguments while all the arguments are valid ones written in its help message? And how can I use defrag.exe properly?


Edit:

Output of fsutil dirty:

---- DIRTY Commands Supported ----

query           Query the dirty bit
set             Set the dirty bit

fsutil dirty query D:

Volume - D: is NOT Dirty

Output of lowercase command is same as the proper case command.


This is my system path environment variable, I use ; as delimiter and split it into multiple lines for better readability:

PS C:\Windows\System32> (gp 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\').Path.split(';')
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\Program Files (x86)\dotnet\
C:\Program Files (x86)\Embarcadero\Studio\21.0\bin
C:\Program Files (x86)\Embarcadero\Studio\21.0\bin64
C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\
C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\
C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\
C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files (x86)\QuickTime\QTSystem\
C:\Program Files (x86)\sbt\bin
C:\Program Files (x86)\scala\bin
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\
C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\
C:\Program Files\7-Zip\
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\dotnet\
C:\Program Files\Elmer 9.0-Release\bin
C:\Program Files\Microsoft MPI\Bin\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\Microsoft SQL Server\150\DTS\Binn\
C:\Program Files\Microsoft SQL Server\150\Tools\Binn\
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\
C:\Program Files\Microsoft VS Code\bin
C:\Program Files\nodejs\
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
C:\Program Files\PowerShell\7\
C:\Program Files\Python39\
C:\Program Files\Python39\Scripts\
C:\Program Files\Tcl86\bin
C:\Strawberry\c\bin
C:\Strawberry\perl\bin
C:\Strawberry\perl\bin\
C:\Strawberry\perl\site\bin
C:\Strawberry\perl\site\bin\
C:\texlive\2021\bin\win32
C:\Users\Public\Documents\Embarcadero\Studio\21.0\Bpl
C:\Windows
C:\Windows\system32
C:\Windows\System32\OpenSSH\
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
D:\CliExec
D:\NSudo
D:\SysinternalsSuite\

I don't delete services:

PS C:\Windows\System32> get-service -displayname *delivery*

Status   Name               DisplayName
------   ----               -----------
Running  DoSvc              Delivery Optimization
2

1 Answer 1

0

Actually there is a simple explanation for this behavior for defrag.exe, I don't know what the invalid command line option specified was at first, because both switches are displayed in its help message, and this is exactly the command I thought that would be the literal translation from the PowerShell command to the defrag.exe one.

Then I tried to run defrag d: /a

And then the magic happens:

Invoking analysis on Tremillia (D:)...


The operation completed successfully.

Post Defragmentation Report:

        Volume Information:
                Volume size                 = 3.00 TB
                Free space                  = 2.62 TB
                Total fragmented space      = 0%
                Largest free space size     = 1.49 TB

        Note: File fragments larger than 64MB are not included in the fragmentation statistics.

        You do not need to defragment this volume.

Then I run defrag d: /d

Invoking defragmentation on Tremillia (D:)...


Pre-Optimization Report:

        Volume Information:
                Volume size                 = 3.00 TB
                Free space                  = 2.62 TB
                Total fragmented space      = 0%
                Largest free space size     = 1.49 TB

        Note: File fragments larger than 64MB are not included in the fragmentation statistics.

The operation completed successfully.

Post Defragmentation Report:

        Volume Information:
                Volume size                 = 3.00 TB
                Free space                  = 2.62 TB
                Total fragmented space      = 0%
                Largest free space size     = 1.49 TB

        Note: File fragments larger than 64MB are not included in the fragmentation statistics.

Both operations completed successfully, but when I tried to use the two switches in one command again, the invalid command line option error pops again.

Guess what? The two switches can't be used together, it seems like they are exclusive to each other and they conflict with each other, but I used those two switches in one command in the optimize-volume command so I thought that would work here, but that process has two stages...

So this error An invalid command line option was specified. (0x89000008) actually means conflicting switches used together, the switches invalidated each other, but the error message definitely could be more clear, and then again there isn't any document I can find that mentioned the two switches /Analyze and /Defrag can't be used together...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .