Microsoft Virtualization Discussions

Script to relate Hyper-V VHDs on Cluster Volumes to their respective LUNs


I was asked to produce a report that showed what VHDs were in use, what Cluster Volume they are on and, subsequently, what LUN it is.  Thanks to Get-NaHyperV that was preposterously easy.  I thought others might benefit from this script so here it is.

You'll need to change the values of $adminID and $pass for your filers

File is also attached.

$VMs=get-nahyperv |select name,storage

$adminID = "CHANGE_ME"

$pass = ConvertTo-SecureString "CHANGE_ME" -AsPlainText -Force

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminID,$pass

$objstorageinfo =@()

foreach ($VM in $VMs){

$storageinfo=$|Select *

foreach ($storageprop in $storageinfo){

If (Test-Path $storageprop.VmDiskResourceName){

$VHDSize   = gi $storageprop.VmDiskResourceName |select @{Name="SizeInGB";Expression={[Math]::Round($_.Length/1GB)}}

$conn=Connect-naController $storageprop.ControllerName -credential $cred

$csv = Get-ClusterSharedVolume $storageprop.ClusterResource

$objcsvSizeInfo =$csv | select -Expand SharedVolumeInfo|select -expand partition

$LUN=Get-NalUN $storageprop.ControllerLunPath|select @{Name="SizeInGB";Expression={[Math]::Round($_.Size/1GB)}},@{Name="UsedSizeInGB";Expression={[Math]::Round($_.SizeUsed/1GB)}}

$lunID = (get-nalunmap $storageprop.ControllerLunPath).lunid

$Vol=Get-NalUN $storageprop.ControllerLunPath|Get-Navol |select name,ContainingAggregate,@{Name="SizeInGB";Expression={[Math]::Round($_.SizeTotal/1GB)}},`



$Aggr = Get-NaAGGr $VOL.ContainingAggregate|select name,@{Name="SizeInGB";Expression={[Math]::Round($_.SizeTotal/1GB)}},`



      $myobj = New-Object PSObject -Property @{

         VMName         = $VM.Name

         VHDPath        = $storageprop.VmDiskResourceName

         VHDSize        = $VHDSize.SizeInGB

         CSVName        = $storageprop.ClusterResource

         CSVPath        = $storageprop.HostDrivePath

         CSVSize        = [Math]::Round($storageprop.size/1GB)

         CSVFreeSize    = [Math]::Round($objcsvSizeInfo.Freespace/1GB)

         HostDisk       = $storageprop.HostDiskName

         LUNPath        = $storageprop.ControllerLunPath

         LUNID          = $lunID

         LUNSize        = $LUN.SizeInGB

         LUNSizeUsed    = $LUN.UsedSizeInGB

         VolName        = $Vol.Name

         VolSize        = $Vol.SizeInGB

         VolUsedSize    = $Vol.UsedSizeInGB

         VolFreeSize    = $Vol.FreeSizeInGB

         AggrName       = $Aggr.Name

         AggrSize       = $Aggr.SizeInGB

         AggrUsedSize   = $Aggr.UsedSizeInGB

         AggrFreeSize   = $Aggr.FreeSizeInGB

         SANName        = $storageprop.ControllerName

      }|select VMName,VHDPath,CSVName,CSVPath,CSVSize,CSVFreeSize,@{Label="CSVUsedSize";Expression = {$_.CSVSize-$_.CSVFreeSize}},HostDisk,`

                LUNPath,LUNID,LUNSize,LUNSizeUsed,@{Label="LUNSizeFree";Expression = {$_.LunSize-$_.LunSizeUsed}},`



      $objstorageinfo += $myobj




$objstorageinfo|export-csv .\NetAPP-VHD.csv -notypeinformation



Thanks for posting!  "preposterously easy" is the goal.


That's a great use of the Cmdlets!  It's cool to see all of the host side info & filer info joined together in one view from the VHD up to the aggregate.

Register for Insight 2021 Digital

INSIGHT 2021 Digital: Meet the Specialists 2

On October 20-22, gear up for a fully digital, totally immersive virtual experience with a downright legendary lineup of world-renowned specialists. Tune in for visionary conversations, solution deep dives, technical sessions and more.

NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner