How to defrag volume using mountpoint?

Solution 1:

You can try to use a different path, not the standard one. Run in powershell: Get-Volume | fl *

Find the required volume which should be optimized and copy path (it should look like - \?\Volume{787efb39-0000-0000-0000-501f00000000})

After this you can simply run defrag command with proper path:

Optimize-Volume -defrag -path "\?\Volume{787efb39-0000-0000-0000-501f00000000}\"

or you can propose this script

$volume = Get-Volume | foreach {$.FileSystemLabel} | Select-String -SimpleMatch "storage1" $path = get-volume -FileSystemLabel $volume | foreach {$.Path} Optimize-Volume -Defrag -Path $path

where -"SimpleMatch" change to the needed volume name

OR just simply use other property:

Optimize-Volume -Defrag -FileSystemLabel "volumename"