Exporting HyperV VM Information from Virtual Machine Manager

By | January 24, 2019

Do you want to export all of your Virtual Machine information like CPU count, Memory and VHD sizes from your Hyper V environment and can’t find anywhere on your Virtual Machine Manager an option to do it? In Citrix Xen Center this is quite easy all you need to do is to go to the Pool Menu -> Export Resource Data and there you go.

In HyperV this is not as easy as that as it is not available via the Virtual Machine Manager, you will need to do it in Powershell! While its not as easy as how you do it in Citrix, you can get a tons of information from it and you can export it in any way you want.

And if you are not well versed in Powershell I provided you the script below to follow, all you need is to run this where your Virtual Machine Manager is installed and change the “YOURHOST” with just a wildcard to get everything or what ever Host Name you want to run your report to.

$Report = @()
 
$VirtualMachines = Get-SCVirtualMachine | Sort-Object -Property Name | Where-Object {$_.HostName -like "YOURHOST*"}
 
#Loop Through all Virtual Machines Found
foreach ($VirtualMachine in $VirtualMachines) 
{
    $VirtualDiskDrives = $VirtualMachine | Get-SCVirtualDiskDrive
 
    #Indicator for the First Virtual Disk Drive, Sets Back to First after one Virtual Machine
    $IsFirstVirtualDiskDrive = $true
 
    foreach ($VirtualDiskDrive in $VirtualDiskDrives)#If its the First Virtual Disk Drive
        if($IsFirstVirtualDiskDrive)
        {
            $Data = New-Object PSObject -property @{
                Name = $VirtualMachine.Name
                CPUCount = $VirtualMachine.CPUCount
                Memory = $VirtualMachine.Memory/1024
                OperatingSystem = $VirtualMachine.OperatingSystem
                Description = $VirtualMachine.Description
                Host = $VirtualMachine.HostName
                VirtualHardDiskName = $VirtualDiskDrive.VirtualHardDisk.Name
                VirtualHardDiskSize = $VirtualDiskDrive.VirtualHardDisk.MaximumSize/1GB
                VirtualHardDiskCurrentSize = [Math]::Round($VirtualHardDisk.VirtualHardDisk.Size/1GB)
                VirtualHardDiskType = $VirtualDiskDrive.VirtualHardDisk.VHDType
                VirtualHardDiskBusType = $VirtualDiskDrive.BusType
                VirtualHardDiskBus = $VirtualDiskDrive.Bus
                VirtualHardDiskLogicalUnitNumber = $VirtualDiskDrive.Lun
                VirtualHardDiskDataStore = $VirtualDiskDrive.VirtualHardDisk.HostVolume
            }
            #Sets Other Virtual Disc Drive in this Virtual Machine as not First
            $IsFirstVirtualDiskDrive = $false
        }
        else 
        #If Second, Third, etc....
        {
            $Data = New-Object PSObject -property @{
                Name = ""
                CPUCount = ""
                Memory = ""
                OperatingSystem = ""
                Description = ""
                            Host = ""
                VirtualHardDiskName = $VirtualDiskDrive.VirtualHardDisk.Name
                VirtualHardDiskSize = $VirtualDiskDrive.VirtualHardDisk.MaximumSize/1GB
                VirtualHardDiskCurrentSize = [Math]::Round($VirtualDiskDrive.VirtualHardDisk.Size/1GB)
                VirtualHardDiskType = $VirtualDiskDrive.VirtualHardDisk.VHDType
                VirtualHardDiskBusType = $VirtualDiskDrive.BusType
                VirtualHardDiskBus = $VirtualDiskDrive.Bus
                VirtualHardDiskLogicalUnitNumber = $VirtualDiskDrive.Lun
                VirtualHardDiskDataStore = $VirtualDiskDrive.VirtualHardDisk.HostVolume
            }
        }
        $Report += $Data 
    }
}
 
#Show on Screen, remove comment below
#$Report
 
#Export to CSV File
$Report | Export-csv "C:\Export\YouHyperVInventory.csv"  -NoTypeInformation
Recommended

One thought on “Exporting HyperV VM Information from Virtual Machine Manager

Leave a Reply

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