When you want to defrag.exe (the built-in Windows one, not the SysInternals Windows NT4 one, so make sure SysInternals comes last in your path) a volume, you have to run it with an elevated UAC Admin token.
But I just found out that you can do this without an Admin token:
C:\Windows\System32>Defrag.exe C: /t /v /u
Microsoft Drive Optimizer
Copyright (c) 2013 Microsoft Corp.
Tracking operation on (C:)...
Performing pass 2:
Free Space Consolidation: 31% complete...
This makes it much easier to separate monitoring scripting from execution.
–jeroen






