PowerShell – Find Dynamic Disks On Your Hyper-V Cluster

I had been looking for a script for a while that would interrogate my Hyper-V clusters and report back with a list of virtual machines running with dynamic VHD’s, as I wanted to convert all existing dynamic VHD’s to a fixed format.

So I wrote the following script to connect to each of the hyper-v hosts within a cluster, read the VHD details of the VM and report back with the VM name, host, path to the virtual disk, disk format and type (hard coded in my instance to dynamic)

$Cluster = "CLUSTERNAME"
$SaveTo = "FILEPATH"
$HVNodes = Get-ClusterNode -Cluster $Cluster
$Results = ForEach ($HVNode in $HVNodes) {
    Invoke-Command -Computername $HVNode.name {   
    ForEach ($VM in (Get-VM)){
    Get-VM -Name $VM.name | Select-Object VMID | get-vhd | Where-Object {$_.vhdType -eq "Dynamic"} | fl @{Label="VirtualMachine";Expression={($VM.name)}},ComputerName, Path, VHDFormat, VHDType
$Results | out-file -FilePath $SaveTo

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 )

Google+ photo

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

Connecting to %s