Resize-UserProfileDisk icon indicating copy to clipboard operation
Resize-UserProfileDisk copied to clipboard

Defrag gives error "The given volume path is invalid. (0x89000001)"

Open Offbeatmammal opened this issue 4 years ago • 4 comments

whever I do a single Vhdx file with -defrag option I get this error:

The given volume path is invalid. (0x89000001)

eg Resize-UserProfileDisk -SingleVhdxFile "E:\UPDs\UVHD-S-1-5-21-3615657673-3089639132-939047325-6172.vhdx" -defrag

Offbeatmammal avatar Feb 25 '21 00:02 Offbeatmammal

Actually $DriveLetter = ($MountResult | Get-Disk | Get-Partition).DriveLetter is not working properly. Pass through should be added at least for $MountResult like $MountResult = Mount-DiskImage $vhdx -PassThru But even then DevicePath is empty (seems more like a bug in PowerShell).

Xerionty avatar Mar 10 '21 15:03 Xerionty

Assuming you don't have any virtual disks mounted a quick fix could be changing the code to: I changed $MountResult = Mount-DiskImage $vhdx -PassThru and $DriveLetter = (Get-Disk | ?{$_.FriendlyName -eq "Msft Virtual Disk"} | Get-Partition).DriveLetter

        if ($defrag) {
            Write-Log -severity Information -message "Defrag parameter detected. Script wil defragging the VHDX-files. Script wil use the defrag.exe with the /x switches."

            foreach ($vhdx in $vhdxArray) {             
                try {
                    Write-Log -severity Information -message " "
                    Write-Log -severity Information -message "Defrag: Try to mount VHDX-file $vhdx..."
                    $MountResult = Mount-DiskImage $vhdx -PassThru
                    Start-Sleep -Seconds 15                    
                    Write-Log -severity Information -message "Defrag: Try to mount VHDX-file $vhdx... Done"
                }
                Catch {
                    $error.clear()
                    $errormessage = $_.exception.message
                    Write-Log -severity Information -message "Defrag: Try to mount VHDX-file $vhdx... Failed. Error: $errormessage" 
                    return
                }

                try {
                    Write-Log -severity Information -message "Defrag: Checking for driveletter mounted $vhdx..." 
                    $DriveLetter = (Get-Disk | ?{$_.FriendlyName -eq "Msft Virtual Disk"} | Get-Partition).DriveLetter
                    Write-Log -severity Information -message "Defrag: Checking for driveletter mounted $vhdx... Done. Detected driveletter: $Driveletter"
                }

Xerionty avatar Mar 11 '21 10:03 Xerionty

Hello,

I have same problem. :(

The fix won't work for me.

Do you have a another solution ?

Thank you

prohand avatar Sep 27 '21 09:09 prohand

Hi,

the fix helped with defrag but sdelete still mentions that the driveletter is wrong or missing.

tapsiturtle avatar Nov 24 '21 07:11 tapsiturtle