The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • Archives

  • Meta

PowerShell is King – Find out what Differencing disks that are in use

Posted by Mikael Nystrom on November 7, 2016

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:

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{
        Script used to Deploy and Configure Fabric
        Created: 2016-11-07
        Version: 1.0
        Author : Mikael Nystrom
        Twitter: @mikael_nystrom
        Blog   :
        Disclaimer: This script is provided "AS IS" with no warranties.

    $VMHardDiskDrives = Get-VMHardDiskDrive -VM (Get-VM)
    $ActiveDisks = foreach($VMHardDiskDrive in $VMHardDiskDrives){
        $Diffs = Get-VHD -Path $VMHardDiskDrive.Path | Where-Object -Property VhdType -EQ -Value Differencing
    $ActiveDisks | Sort-Object | Select-Object -Unique

On my laptop that gives the the following return:

The output.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: