If you enter the Get-VM cmdlet followed by the virtual machine name, you will find that the cmdlet does not display specific information about the virtual hard disk, even if you use the Select-Object cmdlet to display all of the available attributes. So, with that said, the first step is to find the path and file name of the virtual machine’s virtual hard disk. It is possible to incorporate a loop into the script in a way that allows the loop to detect and remove multiple virtual hard disks, but that’s another discussion for another day. Let’s get startedīefore I get started, I just want to point out that in the interest of simplicity, I am going to assume that the virtual machine in question only has one virtual hard disk. In this article, I will show you how it works. It is possible, however, to build a PowerShell script to delete and remove both virtual machines and its virtual hard disks. However, you can also end up in a situation in which your storage is cluttered by orphaned virtual hard disks.
![removem ongo from vm removem ongo from vm](https://venturebeat.com/wp-content/uploads/2019/04/google-cloud-7-open-source-partners.png)
That way, if you want to rebuild the VM, you can use the existing virtual hard disks to do so.
![removem ongo from vm removem ongo from vm](https://shop17860.hstatic.dk/upload_dir/shop/H1633.jpg)
Microsoft presumably leaves the virtual hard disks in place as a safety measure. The problem with this, however, is that when you use the Hyper-V Manager to delete a virtual machine, its virtual hard disks are not deleted, and these orphaned virtual hard disks can consume a significant amount of storage space.
![removem ongo from vm removem ongo from vm](http://img.youtube.com/vi/qI7IgYzytcI/0.jpg)
In fact, VMs can be created or deleted on a whim. Virtual machines tend to have a much shorter lifespan than physical machines.