• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Hyper-V Virtual Machine - Completely Delete in Windows 8


Brink

Administrator
Administrator
mvp
Posts
23,623
Hyper-V Virtual Machine - Completely Delete in Windows 8
This tutorial will show you how to completely delete all traces of a Hyper-V virtual machine all at once from a host Windows 8, 8.1, and Server 2012 PC.
Published by Brink
#1
Category:
ByLine
How to Completely Delete a Hyper-V Virtual Machine in Windows 8, 8.1, and Server 2012
Synopsis
This tutorial will show you how to completely delete all traces of a Hyper-V virtual machine all at once from a host Windows 8, 8.1, and Server 2012 PC.
How to Completely Delete a Hyper-V Virtual Machine in Windows 8, 8.1, and Server 2012


information   Information
The Hyper-V technology provides an environment that you can use to create and manage virtual machines and their resources. Each virtual machine is an isolated, virtualized computer system that is capable of running its own operating system. This allows you to run multiple operating systems at the same time on the same physical computer.

When you delete a virtual machine (VM) in Hyper-V Manager, it will only delete the VM's checkpoints, delete VM's configuration and ID files, and remove the VM from Hyper-V Manager. It will not delete the VM's virtual hard disks and folders though.

This tutorial will show you how to completely delete all traces of a Hyper-V virtual machine all at once from a host Windows 8, 8.1, and Server 2012 PC.

You must be signed in as an administrator to be able to do the steps in this tutorial.

Note   Note
What will be deleted:

  • VM will be removed from Hyper-V Manager
  • All checkpoints created for the VM in Snapshots folder.
  • All virtual hard disks in Virtual Hard Disks folder for the VM.
  • Configuration files and ID in Virtual Machines folder for the VM.
  • All other folders for the VM. For example, the folders the above folders are saved in.

EXAMPLE: Hyper-V Manager
NOTE: The virtual machine names are listed under Virtual Machines at the top in the middle pane.


Hyper-V_Manager.png




Here's How:

1. Shut down and turn off any virtual machine you want to delete.

2. Open an elevated PowerShell.

3. In the elevated PowerShell, type get-vm, and press Enter to see a list of all Hyper-V virtual machine (VM) names on the host PC. Make note of the VM's name (ex: 8.1 Update Enterprise) you want to completely delete. (see screenshot below)

NOTE: If you like you can also see the name of the VM in Hyper-V Manager.
PowerShell_get-vm.png

4. In the elevated PowerShell, type the command below, and press Enter. (see screenshot below)

Code:
Get-VM "[COLOR=#ff0000][B]VM Name[/B][/COLOR]" | %{ Stop-VM -VM $_ -Force; Remove-VM -vm $_ -Force ; Remove-Item -Path $_.Path -Recurse -Force}
Note   Note
Substitute VM Name in the command above with the actual name of the VM from step 2 above.

For example:

Get-VM "8.1 Update Enterprise" | %{ Stop-VM -VM $_ -Force; Remove-VM -vm $_ -Force ; Remove-Item -Path $_.Path -Recurse -Force}


PowerShell_delete-vm.png

5. If the Hyper-V VM is currently running, then click/tap on Exit when prompted, and go to step 7 below. (see screenshot below)
PowerShell_delete-vm-3.png

6. If the Hyper-V VM is not currently running, then you will see the WARNING: The Virtual machine is already in the specified state message just to let you know. There's nothing that needs to be done. (see screenshot below)
PowerShell_delete-vm-B.png

7. When you see the PS C:\Windows\system32> prompt return, the VM has finished being completely deleted. (see screenshots below)

NOTE: This could take a little while to finish.
PowerShell_delete-vm-C.png
PowerShell_delete-vm-2.png

8. When finished, you can close PowerShell if you like.


That's it,
Shawn


 
Last edited by a moderator:

My Computer

System One

  • OS
    64-bit Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model Number
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    250GB Samsung 960 EVO M.2,
    256GB OCZ Vector,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone
#2
Does this tutorial and the two included related tutorials apply to win10?
 

My Computer

System One

  • OS
    win8.1
    Computer type
    PC/Desktop
    CPU
    core I3 4340
    Motherboard
    asus z87a
    Memory
    8GB
    Graphics Card(s)
    radeon 5750
    Sound Card
    x-fi true audio
    Monitor(s) Displays
    gateway generic
    Screen Resolution
    1920x1080
    Hard Drives
    ssd120
    hdd 320gb x 2
    PSU
    500w
    Case
    zalman
    Cooling
    oem
    Keyboard
    ms 4000
    Mouse
    ms4500
    Internet Speed
    dsl 3dn, .75up
    Browser
    firefox
    Antivirus
    MSE

Brink

Administrator
Administrator
mvp
Posts
23,623
#3
Hello trbodden,

Yes, you can use them in Windows 10 as well. :)
 

My Computer

System One

  • OS
    64-bit Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model Number
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    250GB Samsung 960 EVO M.2,
    256GB OCZ Vector,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone

abeaulieu

New Member
Posts
2
#4
Hi, thanks, I will try this in the future, but too late for a bunch of them...

I already deleted the VM from Hyper-v manually, now I am stuck with a bunch of old files.
I could go in and clean them manually, but the names are not always easily matching.
Would there be a way to find the useless files and delete them via a script?

Thanks,
Alex
 

My Computer

System One

  • OS
    Win8.1

Brink

Administrator
Administrator
mvp
Posts
23,623
#5
Hello Alex, and welcome to Eight Forums. :)

Not that I'm aware of after removing the VM name in the Hyper-V Manager.

If you know where you set to store the virtual machine, then you should be able to just delete the VM's folder to completely remove it.
 

My Computer

System One

  • OS
    64-bit Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model Number
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    250GB Samsung 960 EVO M.2,
    256GB OCZ Vector,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone

abeaulieu

New Member
Posts
2
#6
Thanks for the quick response.
My issue is that few "manager" (including me) placed there folder here and there.
I deleted a few unused VM.
Now I need to guest where is what to clean it up.

I'll keep everything as-is for know, but sooner that later I'll have to find a way to clean this up to release space!
 

My Computer

System One

  • OS
    Win8.1

Brink

Administrator
Administrator
mvp
Posts
23,623
#7
In that case, you could see if doing a search with "*.vhd" and "*.vhdx" in File Explorer for the virtual hard disks files may help find their location.
 

My Computer

System One

  • OS
    64-bit Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model Number
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    250GB Samsung 960 EVO M.2,
    256GB OCZ Vector,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone

mato

New Member
Posts
4
#8
I used mentioned script.... I didn't saw any wm manager, so I tried to restart vmms - it is unable to strart - I don't know why. All symlinks are deleted - adding them didn't help. I don't know what to do...
 

My Computer

System One

  • OS
    win

Brink

Administrator
Administrator
mvp
Posts
23,623
#9
Hello mato, and welcome to Eight Forums. :)

Please provide more details about what you are wanting to do.

If you used this tutorial, it will permanently delete any VMs you used it on.
 

My Computer

System One

  • OS
    64-bit Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model Number
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    250GB Samsung 960 EVO M.2,
    256GB OCZ Vector,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone

mato

New Member
Posts
4
#10
I just wanted to delete one specific vm, as described...When I ran mentioned command (with vm name replaced) hyper-v manager just shows 2 my wm's (more than 10 should be displayed). I found, that symlinks of all vm's were deleted, so I recreated them and tried to restart vmms. No luck there, vmms stopped and I am unable to start it. Now my wms are running, but I can't manage them. I am worried, that restart of hypervisor will cause situation - wms not running and me unable to start them....
 

My Computer

System One

  • OS
    win

Brink

Administrator
Administrator
mvp
Posts
23,623
#11

My Computer

System One

  • OS
    64-bit Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model Number
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    250GB Samsung 960 EVO M.2,
    256GB OCZ Vector,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone

mato

New Member
Posts
4
#12
It deleted all non running VM vhds, all symlinks and index file.... I was able to restore virtual machines, which were running during execution of a script.....All others were completely removed...
 

My Computer

System One

  • OS
    win

Brink

Administrator
Administrator
mvp
Posts
23,623
#13
The command will only delete a specific VM, so the only thing I can think of is that you may have made a mistake made with the command for the VM name. :(
 

My Computer

System One

  • OS
    64-bit Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model Number
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    250GB Samsung 960 EVO M.2,
    256GB OCZ Vector,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone

mato

New Member
Posts
4
#14
super important VM's were running, just some testing were off. So almost no damage, but when I ran command and all vm disappeared form manager I almost s**t myself..... :doh:
 
Last edited by a moderator:

My Computer

System One

  • OS
    win

capn0jack

New Member
Posts
1
#15
There's definitely something a little off with that script. On a 2012 R2 HV host I open PS as admin and tried to delete one VM named "OPMANAGER":

Code:
Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.


PS C:\Windows\system32> get-vm


Name          State   CPUUsage(%) MemoryAssigned(M) Uptime     Status
----          -----   ----------- ----------------- ------     ------
devsql2012-02 Running 2           9664              2.10:24:30 Operating normally
IMSQLTEST01   Off     0           0                 00:00:00   Operating normally
OPMANAGER     Off     0           0                 00:00:00   Operating normally
SPICEWORKS    Off     0           0                 00:00:00   Operating normally




PS C:\Windows\system32> Get-VM "OPMANAGER" | %{ Stop-VM -VM $_ -Force; Remove-VM -vm $_ -Force ; Remove-Item -Path $_.Pa
th -Recurse -Force}
WARNING: The virtual machine is already in the specified state.
Remove-Item : Cannot remove item D:\HyperV\Virtual Machines\BB148AF1-1F74-4B74-B8A8-393AB97B6256.xml: The process
cannot access the file 'BB148AF1-1F74-4B74-B8A8-393AB97B6256.xml' because it is being used by another process.
At line:1 char:74
+ Get-VM "OPMANAGER" | %{ Stop-VM -VM $_ -Force; Remove-VM -vm $_ -Force ; Remove- ...
+                                                                          ~~~~~~~
    + CategoryInfo          : WriteError: (BB148AF1-1F74-4B74-B8A8-393AB97B6256.xml:FileInfo) [Remove-Item], IOExcepti
   on
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Cannot remove item D:\HyperV\Virtual Machines: The directory is not empty.
At line:1 char:74
+ Get-VM "OPMANAGER" | %{ Stop-VM -VM $_ -Force; Remove-VM -vm $_ -Force ; Remove- ...
+                                                                          ~~~~~~~
    + CategoryInfo          : WriteError: (Virtual Machines:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
Remove-Item : Cannot remove item D:\HyperV: The directory is not empty.
At line:1 char:74
+ Get-VM "OPMANAGER" | %{ Stop-VM -VM $_ -Force; Remove-VM -vm $_ -Force ; Remove- ...
+                                                                          ~~~~~~~
    + CategoryInfo          : WriteError: (D:\HyperV:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
It did delete the OPMANAGER VM and it didn't appear to delete any others, but it definitely seemed to be trying to delete stuff it shouldn't.

Thanks,
Chaz
 

My Computer

System One

  • OS
    N/A

Users Who Are Viewing This Thread (Users: 0, Guests: 1)