Hyper-V

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

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:

image
The output.

Categories: Hyper-V, PowerShell

Tagged as: ,

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.