Simple VM Inventory

Quicky

Another quicky to get all VMs from your hosts/cluster and display some basic information about them like CPU, memory, disk count and size.

  • I can get it using Windows Admin Center

  • or using PowerShell


    $HyperVHosts = @('Cluster1','Node1','Node2')
    $VMs = Get-VM -ComputerName $HyperVHosts | ForEach-Object {
    Write-Host "Procesing VM {$($PSItem.VMName)}"
    Write-Host "Getting VM {$($PSItem.VMName)} disk information"
    $disks = Get-VHD -VMId $PSItem.VMId -ComputerName $PSItem.ComputerName
    $diskCount = $disks | Measure | Select-Object -ExpandProperty Count
    $diskCurrentSize = $disks | Measure-Object -Sum -Property FileSize | Select-Object -ExpandProperty Sum
    $diskMaximumSize = $disks | Measure-Object -Sum -Property Size | Select-Object -ExpandProperty Sum
    [pscustomobject]@{
    Name = $PSItem.Name
    ComputerName = $PSItem.ComputerName
    MemoryMinimum = [System.Math]::Round($PSItem.MemoryMinimum /1GB,2)
    MemoryMaximum = [System.Math]::Round($PSItem.MemoryMaximum /1GB,2)
    MemoryAssigned = [System.Math]::Round($PSItem.MemoryAssigned /1GB,2)
    ProcessorCount = $PSItem.ProcessorCount
    DisksCount = $diskCount
    DiskCurrentSize = [System.Math]::Round($diskCurrentSize /1GB,2)
    DiskMaximumSize = [System.Math]::Round($diskMaximumSize /1GB,2)
    CreationTime = $PSItem.CreationTime
    }
    }
    $VMs | Format-Table -Wrap

    view raw

    VMInventory.ps1

    hosted with ❤ by GitHub

    The output looks like this:

Leave a comment