How to Delete A VM And A VM Disk From Disk Using Hyper-V PowerShell

How to Delete A VM And A VM Disk From Disk Using Hyper-V PowerShell

How to Delete A VM And A VM Disk From Disk Using Hyper-V PowerShell

In this blog post, I’ll show you How to Delete A VM And A VM Disk From Disk Using Hyper-V PowerShell using a great PowerShell Script for Windows Server 2016 Hyper-V Server.

By default, when we delete a Hyper-V Virtual Machine, the VM gets deleted however the OS Disk and Data Disk are not deleted and they stay on the Storage Disk taking space.

 Delete A VM And A VM Disk From Disk Using Hyper-V PowerShell

Many Admins don’t realize this and after a few years the end up with a large amount of space being wasted because of unused VMs.

To prevent this, I wrote a nice PowerShell script that will delete a specific VM and all the disks associated with it.

To get started, Copy the script to PowerShell ISE.

Change the VM Name In my case the name Is nanot01 and run the code to delete all the disks drive

GET-VM -VMName nanot01 | Get-VMHardDiskDrive | Foreach { Remove-item -path $_.Path -Recurse -Force -Confirm:$False}

Once completed, I’ll run the next line to delete the Virtual Machine

Remove-VM naot01

How to Delete A VM And A VM Disk From Disk Using Hyper-V PowerShell
How to Delete A VM And A VM Disk From Disk Using Hyper-V PowerShell

I find that script very handy in cases where I need to delete unused Virtual Machine from my environment.




Search blogs




Bitnami