I use Hyper-V, in both production as well as for lab. One very effective way to spin up systems very fast is to use differencing disks, it also saves space. So I use differencing disks basically. After a while you tend to have some VM’s in your environment, and when it comes to a lab environment, well lets put it this way, I have disks all over the place.
(The function is on GitHub: https://github.com/DeploymentBunny/Files/tree/master/Tools/Get-VIAActiveDiffDisk)
I need to know what Parent hard drives that are active and in use
So, PowerShell to the rescue. First we get all hard disks that are connected to any of my VM’s, then we grab each disk that has a parent disk, an then we present that. That should give me a list of what parent disks are actually used.
Function Get-VIAActiveDiffDisk{ <# .Synopsis Script used to Deploy and Configure Fabric .DESCRIPTION Created: 2016-11-07 Version: 1.0 Author : Mikael Nystrom Twitter: @mikael_nystrom Blog : http://deploymentbunny.com Disclaimer: This script is provided "AS IS" with no warranties. .EXAMPLE Get-VIAActiveDiffDisk #> [CmdletBinding(SupportsShouldProcess=$true)] param( ) $VMHardDiskDrives = Get-VMHardDiskDrive -VM (Get-VM) $ActiveDisks = foreach($VMHardDiskDrive in $VMHardDiskDrives){ $Diffs = Get-VHD -Path $VMHardDiskDrive.Path | Where-Object -Property VhdType -EQ -Value Differencing $Diffs.ParentPath } $ActiveDisks | Sort-Object | Select-Object -Unique }
On my laptop that gives the the following return:
Categories: Hyper-V, PowerShell