Subscribe

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=$VM.storage|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)}},`

                                 @{Name="UsedSizeInGB";Expression={[Math]::Round($_.SizeUsed/1GB)}},`

                                 @{Name="FreeSizeInGB";Expression={[Math]::Round($_.SizeAvailable/1GB)}}

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

                                                        @{Name="UsedSizeInGB";Expression={[Math]::Round($_.SizeUsed/1GB)}},`

                                                         @{Name="FreeSizeInGB";Expression={[Math]::Round($_.SizeAvailable/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}},`

                VolName,VolSize,VolUsedSize,VolFreeSize,`

                AggrName,AggrSize,AggrUsedSize,AggrFreeSize,SANName

      $objstorageinfo += $myobj

   }

}

}

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

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

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.

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

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