5

I am trying to defrag the volume by optimize-volume cmdlet . I have passed mount point path. But it fails as below.

PS C:\Users\Administrator> Optimize-Volume -Path C:\Testvol1\disk
Optimize-Volume : No MSFT_Volume objects found with property 'Path' equal to 'C:\Testvol1\disk'.  Verify the value of the property and retry.
At line:1 char:1
+ Optimize-Volume -Path C:\Testvol1\disk
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Testvol1\disk:String) [Optimize-Volume], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_Path,Optimize-Volume

How to pass path for Optimize-volume? Or is there any other way to defrag using mounthpath available?

1 Answer 1

4

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"

You must log in to answer this question.

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