Mark Minasi's Tech Forum
Register Calendar Latest Topics Chat
 
 
 


Reply
  Author   Comment  
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 810
Reply with quote  #1 
So I tried it on a VHDX, running off a Server 2012R2.

Server has a C Drive at 96GB expansion out of 127GB.
Deleted 40GB from the Server.
Nothing in the recycle bin.
Couldn't compress the VHDX with Powershell or the GUI while the server was tuned on.
Shut down the VM.
Ran Compression with Powershell, recovered 2GB.....the server went to 94GB.

I remember Wes asking about this in the old forum, but can't remember the answer.

But I do know I have 4 or 5 other servers I need to do this on.

Am I missing something?


__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
downtime

Senior Member
Registered:
Posts: 103
Reply with quote  #2 
May I ask which PowerShell command you have already tried?

I came across this article (with PowerShell command) so was curious to see if this will help you:

https://helgeklein.com/blog/2014/10/compacting-client-hyper-v-vhdx-files/
0
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 810
Reply with quote  #3 
Thats the commands I used, all borrowed from another person very free with their script - http://deploymentbunny.com/2015/06/15/powershell-is-king-compress-compact-optimize-vhd-and-vhdx-files/

Code:

[CmdletBinding()]
Param(
    $VMnames
)
foreach($VMname in $VMnames){
    #Check if VM is running
    Write-Verbose "Checking $VMname"
    if((Get-VM -Name $VMname).State -eq "off" -and (Get-VM -Name $VMname).ParentCheckpointId -eq $null){
    
    #Find the disks
    foreach($VHD in ((Get-VMHardDiskDrive -VMName $VMname).Path)){
        Write-Verbose "Working on $VHD, please wait"
        Write-Verbose "Current size $([math]::truncate($(Get-VHD -Path $VHD).FileSize/ 1GB)) GB"
        Mount-VHD -Path $VHD -NoDriveLetter -ReadOnly
        Optimize-VHD -Path $VHD -Mode Full
        Write-Verbose "Optimize size $([math]::truncate($(Get-VHD -Path $VHD).FileSize/ 1GB)) GB"
        Dismount-VHD -Path $VHD
        Write-Verbose ""
        }
    }
    else{Write-Warning "$VMname is not turned off or has a snapshot, will not be fixed"
    Write-Verbose ""}
    }


The command is 
OptimiseVHDX.ps1 -VMnames "Server Name" -verbose

So my output is pretty

PS C:\temp> .\OptimiseVHDX.ps1 -VMnames "Server Name" -verbose
VERBOSE: Checking Server Name
VERBOSE: Working on V:\Hyper-V\Virtual Hard Disks\Server Name C Drive.vhdx, please wait
VERBOSE: Current size 96 GB
VERBOSE: Optimize size 94 GB
VERBOSE:


__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 228
Reply with quote  #4 
Right, defrag first, then run sdelete -z . If you're still not satisfied with the result, try shrinking the partition in Disk Mgmgt. If it won't shrink to your desired size, you won't get there with Optimize-VHD either.
__________________
Evgenij Smirnov

My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
wobble_wobble

Avatar / Picture

Associate Troublemaker Apprentice
Registered:
Posts: 810
Reply with quote  #5 
I know this was a pipe dream, but I moved it to another disk on the Host just to see.

So new info for me....
Hyper-V leaves the RAM VSV & Bin files behind as well as the VHDK file.
I thought maybe after a moved I might be able to compress it a bit more, but no.

I have gained 20GB (as in I have an extra 20GB even thought the VSV and VHDK is left behind) from somewhere on the move, which is confusing me a lot.

Tried the resize - its having none of it.
Seriously debating Disk2VHD.

Edit - there was a Hyper-V Replica that I removed thinking it may have blocked the online compression. I did have to turn off the server to compress the disk.


__________________
Have you tried turning it off and walking away? The next person can fix it!

New to the forum? Read this
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.