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
C:\Windows\system32\defrag.exe /?
what happens? If you get an invalid command then it has to be system corruption. Which wouldn't be the first time you have experienced system corruption.Dism /Online /Cleanup-Image /RestoreHealth